- 5,150
- 49
- 901
Привет! Короче создал я целиком свою печь. Написал свой TileEntity,контейнер,GUI ,класс печи, и все вроде хорошо! Но происходит следующее: (вы можете это увидеть посмотрев это
https://www.youtube.com/watch?v=rP8pcDgyx78&feature=youtu.be
))
Либо достается стак бревен, либо вообще краш. В чем может быть ошибка(конфликт)?
И собственно сам класс блока
https://www.youtube.com/watch?v=rP8pcDgyx78&feature=youtu.be
))
Либо достается стак бревен, либо вообще краш. В чем может быть ошибка(конфликт)?
package com.example.gopnikmod.MyTestBlockGUI;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
public class TileEntityTestBlock extends TileEntity implements ISidedInventory
{
private static final int[] slotsTop = new int[] {0};
private static final int[] slotsBottom = new int[] {2, 1};
private static final int[] slotsSides = new int[] {1};
/** В ItemStacks что держали эти предметы в настоящее время используется в топку */
private ItemStack[] furnaceItemStacks = new ItemStack[3];
/** Количество номер тика, что печь будет гореть */
public int furnaceBurnTime;
/** Количество тактов, свежую копию на данный момент-сжигание пункт Сохранить в печи сжигания для */
public int currentItemBurnTime;
/** Количество тиков, что данный пункт готовилась */
public int furnaceCookTime;
private String field_145958_o;
private static final String __OBFID = "CL_00000357";
/**
*Возвращает Количество слотов в инвентаре.
*/
public int getSizeInventory()
{
return this.furnaceItemStacks.length;
}
/**
* Возвращает стек в слот i
*/
public ItemStack getStackInSlot(int slot_id)
{
return this.furnaceItemStacks[slot_id];
}
/**
* Удаляет из инвентаря слот (первого аргумента) до указанного числа (второй аргумент) элементов и возвращает их в
* новый стека.
*/
public ItemStack decrStackSize(int slot_id, int stackSize)
{
if (this.furnaceItemStacks[slot_id] != null)
{
ItemStack itemstack;
if (this.furnaceItemStacks[slot_id].stackSize <= stackSize)
{
itemstack = this.furnaceItemStacks[stackSize];
this.furnaceItemStacks[slot_id] = null;
return itemstack;
}
else
{
itemstack = this.furnaceItemStacks[slot_id].splitStack(stackSize);
if (this.furnaceItemStacks[slot_id].stackSize == 0)
{
this.furnaceItemStacks[slot_id] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
/**
* Когда некоторые контейнеры закрываются они называют это на каждый слот, потом бросите все возвращается, как EntityItem -
* как при закрытии интерфейса верстака.
*/
public ItemStack getStackInSlotOnClosing(int slot_id)
{
if (this.furnaceItemStacks[slot_id] != null)
{
ItemStack itemstack = this.furnaceItemStacks[slot_id];
this.furnaceItemStacks[slot_id] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Задает стэка товар в указанный слот в инвентаре (можно крафтить доспехи или разделы).
*/
public void setInventorySlotContents(int slot_id, ItemStack itemStack)
{
this.furnaceItemStacks[slot_id] = itemStack;
if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
{
itemStack.stackSize = this.getInventoryStackLimit();
}
}
/**
*Возвращает название инвентаря
*/
public String getInventoryName()
{
return this.hasCustomInventoryName() ? this.field_145958_o : "container.furnace";
}
/**
* Returns if the inventory is named
*/
public boolean hasCustomInventoryName()
{
return this.field_145958_o != null && this.field_145958_o.length() > 0;
}
public void func_145951_a(String customName)
{
this.field_145958_o = customName;
}
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagList nbttaglist = nbt.getTagList("Items", 10);
this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
byte b0 = nbttagcompound1.getByte("Slot");
if (b0 >= 0 && b0 < this.furnaceItemStacks.length)
{
this.furnaceItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
this.furnaceBurnTime = nbt.getShort("BurnTime");
this.furnaceCookTime = nbt.getShort("CookTime");
this.currentItemBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (nbt.hasKey("CustomName", 8))
{
this.field_145958_o = nbt.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setShort("BurnTime", (short)this.furnaceBurnTime);
nbt.setShort("CookTime", (short)this.furnaceCookTime);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
if (this.furnaceItemStacks != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
this.furnaceItemStacks.writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbt.setTag("Items", nbttaglist);
if (this.hasCustomInventoryName())
{
nbt.setString("CustomName", this.field_145958_o);
}
}
/**
* Возвращает максимальный размер стека для игрового инвентаря.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
*Возвращает целое число между 0 и значением, переданным представляя, как закрыть текущий Элемент является полностью
* готовые
*/
@SideOnly(Side.CLIENT)
public int getCookProgressScaled(int scale)
{
return this.furnaceCookTime * scale / 200;
}
/**
* Возвращает целое число между 0 и значением, переданным представляя, сколько времени осталось гореть по текущему топлива
* пункт, где 0 означает, что элемент истощается и переданное значение означает, что товар свежий
*/
@SideOnly(Side.CLIENT)
public int getBurnTimeRemainingScaled(int scale)
{
if (this.currentItemBurnTime == 0)
{
this.currentItemBurnTime = 200;
}
return this.furnaceBurnTime * scale / this.currentItemBurnTime;
}
/**
* IsBurning печи
*/
public boolean isBurning()
{
return this.furnaceBurnTime > 0;
}
public void updateEntity()
{
boolean flag = this.furnaceBurnTime > 0;
boolean flag1 = false;
if (this.furnaceBurnTime > 0)
{
--this.furnaceBurnTime;
}
if (!this.worldObj.isRemote)
{
if (this.furnaceBurnTime != 0 || this.furnaceItemStacks[1] != null && this.furnaceItemStacks[0] != null)
{
if (this.furnaceBurnTime == 0 && this.canSmelt())
{
this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (this.furnaceBurnTime > 0)
{
flag1 = true;
if (this.furnaceItemStacks[1] != null)
{
--this.furnaceItemStacks[1].stackSize;
if (this.furnaceItemStacks[1].stackSize == 0)
{
this.furnaceItemStacks[1] = furnaceItemStacks[1].getItem().getContainerItem(furnaceItemStacks[1]);
}
}
}
}
if (this.isBurning() && this.canSmelt())
{
++this.furnaceCookTime;
if (this.furnaceCookTime == 200)
{
this.furnaceCookTime = 0;
this.smeltItem();
flag1 = true;
}
}
else
{
this.furnaceCookTime = 0;
}
}
if (flag != this.furnaceBurnTime > 0)
{
flag1 = true;
MyTestBlock1.updateFurnaceBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
if (flag1)
{
this.markDirty();
}
}
/**
* Возвращает True, если печь может выплавлять элемента, т. е. элемента источника, стек назначения не полный и т. д.
*/
private boolean canSmelt()
{
if (this.furnaceItemStacks[0] == null)
{
return false;
}
else
{
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]);
if (itemstack == null) return false;
if (this.furnaceItemStacks[2] == null) return true;
if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false;
int result = furnaceItemStacks[2].stackSize + itemstack.stackSize;
return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
}
}
/**
* Превратить один элемент из стека источник печи в соответствующий выплавляют элемента в стек результат топку
*/
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]);
if (this.furnaceItemStacks[2] == null)
{
this.furnaceItemStacks[2] = itemstack.copy();
}
else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem())
{
this.furnaceItemStacks[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
}
--this.furnaceItemStacks[0].stackSize;
if (this.furnaceItemStacks[0].stackSize <= 0)
{
this.furnaceItemStacks[0] = null;
}
}
}
/**
* Возвращает количество тиков, что поставляемый товар топливо будет держать горящую топку, или 0, Если элемент не
* топливо
*/
public static int getItemBurnTime(ItemStack itemStack)
{
if (itemStack == null)
{
return 0;
}
else
{
Item item = itemStack.getItem();
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air)
{
Block block = Block.getBlockFromItem(item);
if (block == Blocks.wooden_slab)
{
return 150;
}
if (block.getMaterial() == Material.wood)
{
return 300;
}
if (block == Blocks.coal_block)
{
return 16000;
}
}
if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemHoe && ((ItemHoe)item).getToolMaterialName().equals("WOOD")) return 200;
if (item == Items.stick) return 100;
if (item == Items.coal) return 1600;
if (item == Items.lava_bucket) return 20000;
if (item == Item.getItemFromBlock(Blocks.sapling)) return 100;
if (item == Items.blaze_rod) return 2400;
return GameRegistry.getFuelValue(itemStack);
}
}
public static boolean isItemFuel(ItemStack itemStack)
{
/**
* Возвращает количество тиков, что поставляемый товар топливо будет держать горящую топку, или 0, Если элемент не
* топливо
*/
return getItemBurnTime(itemStack) > 0;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
}
public void openInventory() {}
public void closeInventory() {}
/**
* Возвращает True, если автоматизация позволила вставить стэка (без учета размера стека) в данный слот.
*/
public boolean isItemValidForSlot(int slot_id, ItemStack itemStack)
{
return slot_id == 2 ? false : (slot_id == 1 ? isItemFuel(itemStack) : true);
}
/**
* Возвращает массив, содержащий индексы слоты, которые могут быть доступны по автоматизации по данной стороне
* блок.
*/
public int[] getAccessibleSlotsFromSide(int side)
{
return side == 0 ? slotsBottom : (side == 1 ? slotsTop : slotsSides);
}
/**
* Возвращает True, если автоматика может включить данный пункт в данный слот от данной стороны. Аргументы: Slot, item,
* бок
*/
public boolean canInsertItem(int slot_id, ItemStack itemStack, int side)
{
return this.isItemValidForSlot(slot_id, itemStack);
}
/**
* Возвращает True, если автоматизация может извлечь данный элемент в данный слот от данной стороны. Аргументы: Slot, item,
* бок
*/
public boolean canExtractItem(int slot_id, ItemStack itemStack, int side)
{
return side != 0 || slot_id != 1 || itemStack.getItem() == Items.bucket;
}
}
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
public class TileEntityTestBlock extends TileEntity implements ISidedInventory
{
private static final int[] slotsTop = new int[] {0};
private static final int[] slotsBottom = new int[] {2, 1};
private static final int[] slotsSides = new int[] {1};
/** В ItemStacks что держали эти предметы в настоящее время используется в топку */
private ItemStack[] furnaceItemStacks = new ItemStack[3];
/** Количество номер тика, что печь будет гореть */
public int furnaceBurnTime;
/** Количество тактов, свежую копию на данный момент-сжигание пункт Сохранить в печи сжигания для */
public int currentItemBurnTime;
/** Количество тиков, что данный пункт готовилась */
public int furnaceCookTime;
private String field_145958_o;
private static final String __OBFID = "CL_00000357";
/**
*Возвращает Количество слотов в инвентаре.
*/
public int getSizeInventory()
{
return this.furnaceItemStacks.length;
}
/**
* Возвращает стек в слот i
*/
public ItemStack getStackInSlot(int slot_id)
{
return this.furnaceItemStacks[slot_id];
}
/**
* Удаляет из инвентаря слот (первого аргумента) до указанного числа (второй аргумент) элементов и возвращает их в
* новый стека.
*/
public ItemStack decrStackSize(int slot_id, int stackSize)
{
if (this.furnaceItemStacks[slot_id] != null)
{
ItemStack itemstack;
if (this.furnaceItemStacks[slot_id].stackSize <= stackSize)
{
itemstack = this.furnaceItemStacks[stackSize];
this.furnaceItemStacks[slot_id] = null;
return itemstack;
}
else
{
itemstack = this.furnaceItemStacks[slot_id].splitStack(stackSize);
if (this.furnaceItemStacks[slot_id].stackSize == 0)
{
this.furnaceItemStacks[slot_id] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
/**
* Когда некоторые контейнеры закрываются они называют это на каждый слот, потом бросите все возвращается, как EntityItem -
* как при закрытии интерфейса верстака.
*/
public ItemStack getStackInSlotOnClosing(int slot_id)
{
if (this.furnaceItemStacks[slot_id] != null)
{
ItemStack itemstack = this.furnaceItemStacks[slot_id];
this.furnaceItemStacks[slot_id] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Задает стэка товар в указанный слот в инвентаре (можно крафтить доспехи или разделы).
*/
public void setInventorySlotContents(int slot_id, ItemStack itemStack)
{
this.furnaceItemStacks[slot_id] = itemStack;
if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
{
itemStack.stackSize = this.getInventoryStackLimit();
}
}
/**
*Возвращает название инвентаря
*/
public String getInventoryName()
{
return this.hasCustomInventoryName() ? this.field_145958_o : "container.furnace";
}
/**
* Returns if the inventory is named
*/
public boolean hasCustomInventoryName()
{
return this.field_145958_o != null && this.field_145958_o.length() > 0;
}
public void func_145951_a(String customName)
{
this.field_145958_o = customName;
}
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagList nbttaglist = nbt.getTagList("Items", 10);
this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
byte b0 = nbttagcompound1.getByte("Slot");
if (b0 >= 0 && b0 < this.furnaceItemStacks.length)
{
this.furnaceItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
this.furnaceBurnTime = nbt.getShort("BurnTime");
this.furnaceCookTime = nbt.getShort("CookTime");
this.currentItemBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (nbt.hasKey("CustomName", 8))
{
this.field_145958_o = nbt.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setShort("BurnTime", (short)this.furnaceBurnTime);
nbt.setShort("CookTime", (short)this.furnaceCookTime);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
if (this.furnaceItemStacks != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
this.furnaceItemStacks.writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbt.setTag("Items", nbttaglist);
if (this.hasCustomInventoryName())
{
nbt.setString("CustomName", this.field_145958_o);
}
}
/**
* Возвращает максимальный размер стека для игрового инвентаря.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
*Возвращает целое число между 0 и значением, переданным представляя, как закрыть текущий Элемент является полностью
* готовые
*/
@SideOnly(Side.CLIENT)
public int getCookProgressScaled(int scale)
{
return this.furnaceCookTime * scale / 200;
}
/**
* Возвращает целое число между 0 и значением, переданным представляя, сколько времени осталось гореть по текущему топлива
* пункт, где 0 означает, что элемент истощается и переданное значение означает, что товар свежий
*/
@SideOnly(Side.CLIENT)
public int getBurnTimeRemainingScaled(int scale)
{
if (this.currentItemBurnTime == 0)
{
this.currentItemBurnTime = 200;
}
return this.furnaceBurnTime * scale / this.currentItemBurnTime;
}
/**
* IsBurning печи
*/
public boolean isBurning()
{
return this.furnaceBurnTime > 0;
}
public void updateEntity()
{
boolean flag = this.furnaceBurnTime > 0;
boolean flag1 = false;
if (this.furnaceBurnTime > 0)
{
--this.furnaceBurnTime;
}
if (!this.worldObj.isRemote)
{
if (this.furnaceBurnTime != 0 || this.furnaceItemStacks[1] != null && this.furnaceItemStacks[0] != null)
{
if (this.furnaceBurnTime == 0 && this.canSmelt())
{
this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (this.furnaceBurnTime > 0)
{
flag1 = true;
if (this.furnaceItemStacks[1] != null)
{
--this.furnaceItemStacks[1].stackSize;
if (this.furnaceItemStacks[1].stackSize == 0)
{
this.furnaceItemStacks[1] = furnaceItemStacks[1].getItem().getContainerItem(furnaceItemStacks[1]);
}
}
}
}
if (this.isBurning() && this.canSmelt())
{
++this.furnaceCookTime;
if (this.furnaceCookTime == 200)
{
this.furnaceCookTime = 0;
this.smeltItem();
flag1 = true;
}
}
else
{
this.furnaceCookTime = 0;
}
}
if (flag != this.furnaceBurnTime > 0)
{
flag1 = true;
MyTestBlock1.updateFurnaceBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
if (flag1)
{
this.markDirty();
}
}
/**
* Возвращает True, если печь может выплавлять элемента, т. е. элемента источника, стек назначения не полный и т. д.
*/
private boolean canSmelt()
{
if (this.furnaceItemStacks[0] == null)
{
return false;
}
else
{
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]);
if (itemstack == null) return false;
if (this.furnaceItemStacks[2] == null) return true;
if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false;
int result = furnaceItemStacks[2].stackSize + itemstack.stackSize;
return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
}
}
/**
* Превратить один элемент из стека источник печи в соответствующий выплавляют элемента в стек результат топку
*/
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[0]);
if (this.furnaceItemStacks[2] == null)
{
this.furnaceItemStacks[2] = itemstack.copy();
}
else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem())
{
this.furnaceItemStacks[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
}
--this.furnaceItemStacks[0].stackSize;
if (this.furnaceItemStacks[0].stackSize <= 0)
{
this.furnaceItemStacks[0] = null;
}
}
}
/**
* Возвращает количество тиков, что поставляемый товар топливо будет держать горящую топку, или 0, Если элемент не
* топливо
*/
public static int getItemBurnTime(ItemStack itemStack)
{
if (itemStack == null)
{
return 0;
}
else
{
Item item = itemStack.getItem();
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air)
{
Block block = Block.getBlockFromItem(item);
if (block == Blocks.wooden_slab)
{
return 150;
}
if (block.getMaterial() == Material.wood)
{
return 300;
}
if (block == Blocks.coal_block)
{
return 16000;
}
}
if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemHoe && ((ItemHoe)item).getToolMaterialName().equals("WOOD")) return 200;
if (item == Items.stick) return 100;
if (item == Items.coal) return 1600;
if (item == Items.lava_bucket) return 20000;
if (item == Item.getItemFromBlock(Blocks.sapling)) return 100;
if (item == Items.blaze_rod) return 2400;
return GameRegistry.getFuelValue(itemStack);
}
}
public static boolean isItemFuel(ItemStack itemStack)
{
/**
* Возвращает количество тиков, что поставляемый товар топливо будет держать горящую топку, или 0, Если элемент не
* топливо
*/
return getItemBurnTime(itemStack) > 0;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
}
public void openInventory() {}
public void closeInventory() {}
/**
* Возвращает True, если автоматизация позволила вставить стэка (без учета размера стека) в данный слот.
*/
public boolean isItemValidForSlot(int slot_id, ItemStack itemStack)
{
return slot_id == 2 ? false : (slot_id == 1 ? isItemFuel(itemStack) : true);
}
/**
* Возвращает массив, содержащий индексы слоты, которые могут быть доступны по автоматизации по данной стороне
* блок.
*/
public int[] getAccessibleSlotsFromSide(int side)
{
return side == 0 ? slotsBottom : (side == 1 ? slotsTop : slotsSides);
}
/**
* Возвращает True, если автоматика может включить данный пункт в данный слот от данной стороны. Аргументы: Slot, item,
* бок
*/
public boolean canInsertItem(int slot_id, ItemStack itemStack, int side)
{
return this.isItemValidForSlot(slot_id, itemStack);
}
/**
* Возвращает True, если автоматизация может извлечь данный элемент в данный слот от данной стороны. Аргументы: Slot, item,
* бок
*/
public boolean canExtractItem(int slot_id, ItemStack itemStack, int side)
{
return side != 0 || slot_id != 1 || itemStack.getItem() == Items.bucket;
}
}
package com.example.gopnikmod.MyTestBlockGUI;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ContainerTestBlock extends Container
{
private TileEntityTestBlock tileFurnace;
private int lastCookTime;
private int lastBurnTime;
private int lastItemBurnTime;
private static final String __OBFID = "CL_00001748";
public ContainerTestBlock(InventoryPlayer player, TileEntityTestBlock TileEntityTestBlock)
{
this.tileFurnace = TileEntityTestBlock;
this.addSlotToContainer(new Slot(TileEntityTestBlock, 0, 56, 17));
this.addSlotToContainer(new Slot(TileEntityTestBlock, 1, 56, 53));
this.addSlotToContainer(new SlotFurnace(player.player, TileEntityTestBlock, 2, 116, 35));
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142));
}
}
public void addCraftingToCrafters(ICrafting p_75132_1_)
{
super.addCraftingToCrafters(p_75132_1_);
p_75132_1_.sendProgressBarUpdate(this, 0, this.tileFurnace.furnaceCookTime);
p_75132_1_.sendProgressBarUpdate(this, 1, this.tileFurnace.furnaceBurnTime);
p_75132_1_.sendProgressBarUpdate(this, 2, this.tileFurnace.currentItemBurnTime);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting)this.crafters.get(i);
if (this.lastCookTime != this.tileFurnace.furnaceCookTime)
{
icrafting.sendProgressBarUpdate(this, 0, this.tileFurnace.furnaceCookTime);
}
if (this.lastBurnTime != this.tileFurnace.furnaceBurnTime)
{
icrafting.sendProgressBarUpdate(this, 1, this.tileFurnace.furnaceBurnTime);
}
if (this.lastItemBurnTime != this.tileFurnace.currentItemBurnTime)
{
icrafting.sendProgressBarUpdate(this, 2, this.tileFurnace.currentItemBurnTime);
}
}
this.lastCookTime = this.tileFurnace.furnaceCookTime;
this.lastBurnTime = this.tileFurnace.furnaceBurnTime;
this.lastItemBurnTime = this.tileFurnace.currentItemBurnTime;
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int p_75137_1_, int p_75137_2_)
{
if (p_75137_1_ == 0)
{
this.tileFurnace.furnaceCookTime = p_75137_2_;
}
if (p_75137_1_ == 1)
{
this.tileFurnace.furnaceBurnTime = p_75137_2_;
}
if (p_75137_1_ == 2)
{
this.tileFurnace.currentItemBurnTime = p_75137_2_;
}
}
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
return this.tileFurnace.isUseableByPlayer(p_75145_1_);
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(p_82846_2_);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (p_82846_2_ == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (p_82846_2_ != 1 && p_82846_2_ != 0)
{
if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return null;
}
}
else if (TileEntityTestBlock.isItemFuel(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 1, 2, false))
{
return null;
}
}
else if (p_82846_2_ >= 3 && p_82846_2_ < 30)
{
if (!this.mergeItemStack(itemstack1, 30, 39, false))
{
return null;
}
}
else if (p_82846_2_ >= 30 && p_82846_2_ < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(p_82846_1_, itemstack1);
}
return itemstack;
}
}
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ContainerTestBlock extends Container
{
private TileEntityTestBlock tileFurnace;
private int lastCookTime;
private int lastBurnTime;
private int lastItemBurnTime;
private static final String __OBFID = "CL_00001748";
public ContainerTestBlock(InventoryPlayer player, TileEntityTestBlock TileEntityTestBlock)
{
this.tileFurnace = TileEntityTestBlock;
this.addSlotToContainer(new Slot(TileEntityTestBlock, 0, 56, 17));
this.addSlotToContainer(new Slot(TileEntityTestBlock, 1, 56, 53));
this.addSlotToContainer(new SlotFurnace(player.player, TileEntityTestBlock, 2, 116, 35));
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142));
}
}
public void addCraftingToCrafters(ICrafting p_75132_1_)
{
super.addCraftingToCrafters(p_75132_1_);
p_75132_1_.sendProgressBarUpdate(this, 0, this.tileFurnace.furnaceCookTime);
p_75132_1_.sendProgressBarUpdate(this, 1, this.tileFurnace.furnaceBurnTime);
p_75132_1_.sendProgressBarUpdate(this, 2, this.tileFurnace.currentItemBurnTime);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting)this.crafters.get(i);
if (this.lastCookTime != this.tileFurnace.furnaceCookTime)
{
icrafting.sendProgressBarUpdate(this, 0, this.tileFurnace.furnaceCookTime);
}
if (this.lastBurnTime != this.tileFurnace.furnaceBurnTime)
{
icrafting.sendProgressBarUpdate(this, 1, this.tileFurnace.furnaceBurnTime);
}
if (this.lastItemBurnTime != this.tileFurnace.currentItemBurnTime)
{
icrafting.sendProgressBarUpdate(this, 2, this.tileFurnace.currentItemBurnTime);
}
}
this.lastCookTime = this.tileFurnace.furnaceCookTime;
this.lastBurnTime = this.tileFurnace.furnaceBurnTime;
this.lastItemBurnTime = this.tileFurnace.currentItemBurnTime;
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int p_75137_1_, int p_75137_2_)
{
if (p_75137_1_ == 0)
{
this.tileFurnace.furnaceCookTime = p_75137_2_;
}
if (p_75137_1_ == 1)
{
this.tileFurnace.furnaceBurnTime = p_75137_2_;
}
if (p_75137_1_ == 2)
{
this.tileFurnace.currentItemBurnTime = p_75137_2_;
}
}
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
return this.tileFurnace.isUseableByPlayer(p_75145_1_);
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(p_82846_2_);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (p_82846_2_ == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (p_82846_2_ != 1 && p_82846_2_ != 0)
{
if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return null;
}
}
else if (TileEntityTestBlock.isItemFuel(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 1, 2, false))
{
return null;
}
}
else if (p_82846_2_ >= 3 && p_82846_2_ < 30)
{
if (!this.mergeItemStack(itemstack1, 30, 39, false))
{
return null;
}
}
else if (p_82846_2_ >= 30 && p_82846_2_ < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(p_82846_1_, itemstack1);
}
return itemstack;
}
}
package com.example.gopnikmod.MyTestBlockGUI;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerFurnace;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiTestBlock extends GuiContainer
{
private static final ResourceLocation furnaceGuiTextures = new ResourceLocation("textures/gui/container/furnace.png");
private TileEntityTestBlock tileFurnace;
private static final String __OBFID = "CL_00000758";
public GuiTestBlock(InventoryPlayer inventoryPlayer, TileEntityTestBlock tileFurnace)
{
super(new ContainerTestBlock(inventoryPlayer, tileFurnace));
this.tileFurnace = tileFurnace;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tileFurnace.hasCustomInventoryName() ? this.tileFurnace.getInventoryName() : I18n.format(this.tileFurnace.getInventoryName(), new Object[0]);
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
}
protected void drawGuiContainerBackgroundLayer(float parTick, int mouseX, int mouseY)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
if (this.tileFurnace.isBurning())
{
int i1 = this.tileFurnace.getBurnTimeRemainingScaled(13);
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1);
i1 = this.tileFurnace.getCookProgressScaled(24);
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
}
}
}
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerFurnace;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiTestBlock extends GuiContainer
{
private static final ResourceLocation furnaceGuiTextures = new ResourceLocation("textures/gui/container/furnace.png");
private TileEntityTestBlock tileFurnace;
private static final String __OBFID = "CL_00000758";
public GuiTestBlock(InventoryPlayer inventoryPlayer, TileEntityTestBlock tileFurnace)
{
super(new ContainerTestBlock(inventoryPlayer, tileFurnace));
this.tileFurnace = tileFurnace;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tileFurnace.hasCustomInventoryName() ? this.tileFurnace.getInventoryName() : I18n.format(this.tileFurnace.getInventoryName(), new Object[0]);
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
}
protected void drawGuiContainerBackgroundLayer(float parTick, int mouseX, int mouseY)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
if (this.tileFurnace.isBurning())
{
int i1 = this.tileFurnace.getBurnTimeRemainingScaled(13);
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1);
i1 = this.tileFurnace.getCookProgressScaled(24);
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
}
}
}
package com.example.gopnikmod.MyTestBlockGUI;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import com.example.gopnikmod.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class MyTestBlock1 extends BlockContainer
{
private final Random field_149933_a = new Random();
private final boolean field_149932_b;
private static boolean field_149934_M;
@SideOnly(Side.CLIENT)
private IIcon field_149935_N;
@SideOnly(Side.CLIENT)
private IIcon field_149936_O;
private static final String __OBFID = "CL_00000248";
public MyTestBlock1(boolean p_i45407_1_)
{
super(Material.rock);
this.field_149932_b = p_i45407_1_;
}
public Item getItemDropped(int metadata, Random random, int fortune)
{
return Item.getItemFromBlock(Blocks.furnace);
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
this.func_149930_e(world, x, y, z);
}
private void func_149930_e(World world, int x, int y, int z)
{
if (!world.isRemote)
{
Block block = world.getBlock(x, y, z - 1);
Block block1 = world.getBlock(x, y, z + 1);
Block block2 = world.getBlock(x - 1, y, z);
Block block3 = world.getBlock(x + 1, y, z);
byte b0 = 3;
if (block.func_149730_j() && !block1.func_149730_j())
{
b0 = 3;
}
if (block1.func_149730_j() && !block.func_149730_j())
{
b0 = 2;
}
if (block2.func_149730_j() && !block3.func_149730_j())
{
b0 = 5;
}
if (block3.func_149730_j() && !block2.func_149730_j())
{
b0 = 4;
}
world.setBlockMetadataWithNotify(x, y, z, b0, 2);
}
}
/**
* Gets the block's texture. Args: side, meta
*/
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta)
{
return side == 1 ? this.field_149935_N : (meta == 0 ? this.field_149935_N : (side != meta ? this.blockIcon : this.field_149936_O));
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister p_149651_1_)
{
this.blockIcon = p_149651_1_.registerIcon("furnace_side");
this.field_149936_O = p_149651_1_.registerIcon(this.field_149932_b ? "furnace_front_on" : "furnace_front_off");
this.field_149935_N = p_149651_1_.registerIcon("furnace_top");
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (world.isRemote)
{
return true;
}
else
{
TileEntityTestBlock tileentityfurnace = (TileEntityTestBlock)world.getTileEntity(x, y, z);
if (tileentityfurnace != null)
{
player.openGui(gopnikmod.instanse,1, world, x, y, z);
}
return true;
}
}
/**
* Update which block the furnace is using depending on whether or not it is burning
*/
public static void updateFurnaceBlockState(boolean myX, World world, int x, int y, int z)
{
int l = world.getBlockMetadata(x, y, z);
TileEntityTestBlock tileentity = (TileEntityTestBlock) world.getTileEntity(x, y, z);
field_149934_M = true;
if (myX)
{
world.setBlock(x, y, z, gopnikmod.MyTestBlock2);
}
else
{
world.setBlock(x, y, z, gopnikmod.MyTestBlock1);
}
field_149934_M = false;
world.setBlockMetadataWithNotify(x, y, z, l, 2);
if (tileentity != null)
{
tileentity.validate();
world.setTileEntity(x, y, z, tileentity);
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntityTestBlock createNewTileEntity(World world, int metadata)
{
return new TileEntityTestBlock();
}
/**
* Called when the block is placed in the world.
*/
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase eLB, ItemStack itemStack)
{
int l = MathHelper.floor_double((double)(eLB.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
if (l == 0)
{
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (l == 1)
{
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
if (l == 2)
{
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if (l == 3)
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
if (itemStack.hasDisplayName())
{
((TileEntityTestBlock)world.getTileEntity(x, y, z)).func_145951_a(itemStack.getDisplayName());
}
}
public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
{
if (!field_149934_M)
{
TileEntityTestBlock tileentityfurnace = (TileEntityTestBlock)world.getTileEntity(x, y, z);
if (tileentityfurnace != null)
{
for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1)
{
ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
if (itemstack != null)
{
float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int j1 = this.field_149933_a.nextInt(21) + 10;
if (j1 > itemstack.stackSize)
{
j1 = itemstack.stackSize;
}
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
float f3 = 0.05F;
entityitem.motionX = (double)((float)this.field_149933_a.nextGaussian() * f3);
entityitem.motionY = (double)((float)this.field_149933_a.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double)((float)this.field_149933_a.nextGaussian() * f3);
world.spawnEntityInWorld(entityitem);
}
}
}
world.func_147453_f(x, y, z, block);
}
}
super.breakBlock(world, x, y, z, block, metadata);
}
/**
* A randomly called display update to be able to add particles or other items for display
*/
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random random)
{
if (this.field_149932_b)
{
int l = world.getBlockMetadata(x, y, z);
float f = (float)x + 0.5F;
float f1 = (float)y + 0.0F + random.nextFloat() * 6.0F / 16.0F;
float f2 = (float)z + 0.5F;
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
if (l == 4)
{
world.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
}
else if (l == 5)
{
world.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
}
else if (l == 2)
{
world.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
}
else if (l == 3)
{
world.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
}
}
}
/**
* If this returns true, then comparators facing away from this block will use the value from
* getComparatorInputOverride instead of the actual redstone signal strength.
*/
public boolean hasComparatorInputOverride()
{
return true;
}
/**
* If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
* strength when this block inputs to a comparator.
*/
public int getComparatorInputOverride(World world, int x, int y, int z, int direction)
{
return Container.calcRedstoneFromInventory((IInventory)world.getTileEntity(x, y, z));
}
/**
* Gets an item for the block being called on. Args: world, x, y, z
*/
@SideOnly(Side.CLIENT)
public Item getItem(World world, int x, int y, int z)
{
return Item.getItemFromBlock(Blocks.furnace);
}
}
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import com.example.gopnikmod.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class MyTestBlock1 extends BlockContainer
{
private final Random field_149933_a = new Random();
private final boolean field_149932_b;
private static boolean field_149934_M;
@SideOnly(Side.CLIENT)
private IIcon field_149935_N;
@SideOnly(Side.CLIENT)
private IIcon field_149936_O;
private static final String __OBFID = "CL_00000248";
public MyTestBlock1(boolean p_i45407_1_)
{
super(Material.rock);
this.field_149932_b = p_i45407_1_;
}
public Item getItemDropped(int metadata, Random random, int fortune)
{
return Item.getItemFromBlock(Blocks.furnace);
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
this.func_149930_e(world, x, y, z);
}
private void func_149930_e(World world, int x, int y, int z)
{
if (!world.isRemote)
{
Block block = world.getBlock(x, y, z - 1);
Block block1 = world.getBlock(x, y, z + 1);
Block block2 = world.getBlock(x - 1, y, z);
Block block3 = world.getBlock(x + 1, y, z);
byte b0 = 3;
if (block.func_149730_j() && !block1.func_149730_j())
{
b0 = 3;
}
if (block1.func_149730_j() && !block.func_149730_j())
{
b0 = 2;
}
if (block2.func_149730_j() && !block3.func_149730_j())
{
b0 = 5;
}
if (block3.func_149730_j() && !block2.func_149730_j())
{
b0 = 4;
}
world.setBlockMetadataWithNotify(x, y, z, b0, 2);
}
}
/**
* Gets the block's texture. Args: side, meta
*/
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta)
{
return side == 1 ? this.field_149935_N : (meta == 0 ? this.field_149935_N : (side != meta ? this.blockIcon : this.field_149936_O));
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister p_149651_1_)
{
this.blockIcon = p_149651_1_.registerIcon("furnace_side");
this.field_149936_O = p_149651_1_.registerIcon(this.field_149932_b ? "furnace_front_on" : "furnace_front_off");
this.field_149935_N = p_149651_1_.registerIcon("furnace_top");
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (world.isRemote)
{
return true;
}
else
{
TileEntityTestBlock tileentityfurnace = (TileEntityTestBlock)world.getTileEntity(x, y, z);
if (tileentityfurnace != null)
{
player.openGui(gopnikmod.instanse,1, world, x, y, z);
}
return true;
}
}
/**
* Update which block the furnace is using depending on whether or not it is burning
*/
public static void updateFurnaceBlockState(boolean myX, World world, int x, int y, int z)
{
int l = world.getBlockMetadata(x, y, z);
TileEntityTestBlock tileentity = (TileEntityTestBlock) world.getTileEntity(x, y, z);
field_149934_M = true;
if (myX)
{
world.setBlock(x, y, z, gopnikmod.MyTestBlock2);
}
else
{
world.setBlock(x, y, z, gopnikmod.MyTestBlock1);
}
field_149934_M = false;
world.setBlockMetadataWithNotify(x, y, z, l, 2);
if (tileentity != null)
{
tileentity.validate();
world.setTileEntity(x, y, z, tileentity);
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntityTestBlock createNewTileEntity(World world, int metadata)
{
return new TileEntityTestBlock();
}
/**
* Called when the block is placed in the world.
*/
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase eLB, ItemStack itemStack)
{
int l = MathHelper.floor_double((double)(eLB.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
if (l == 0)
{
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (l == 1)
{
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
if (l == 2)
{
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if (l == 3)
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
if (itemStack.hasDisplayName())
{
((TileEntityTestBlock)world.getTileEntity(x, y, z)).func_145951_a(itemStack.getDisplayName());
}
}
public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
{
if (!field_149934_M)
{
TileEntityTestBlock tileentityfurnace = (TileEntityTestBlock)world.getTileEntity(x, y, z);
if (tileentityfurnace != null)
{
for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1)
{
ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
if (itemstack != null)
{
float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int j1 = this.field_149933_a.nextInt(21) + 10;
if (j1 > itemstack.stackSize)
{
j1 = itemstack.stackSize;
}
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
float f3 = 0.05F;
entityitem.motionX = (double)((float)this.field_149933_a.nextGaussian() * f3);
entityitem.motionY = (double)((float)this.field_149933_a.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double)((float)this.field_149933_a.nextGaussian() * f3);
world.spawnEntityInWorld(entityitem);
}
}
}
world.func_147453_f(x, y, z, block);
}
}
super.breakBlock(world, x, y, z, block, metadata);
}
/**
* A randomly called display update to be able to add particles or other items for display
*/
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random random)
{
if (this.field_149932_b)
{
int l = world.getBlockMetadata(x, y, z);
float f = (float)x + 0.5F;
float f1 = (float)y + 0.0F + random.nextFloat() * 6.0F / 16.0F;
float f2 = (float)z + 0.5F;
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
if (l == 4)
{
world.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
}
else if (l == 5)
{
world.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
}
else if (l == 2)
{
world.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
}
else if (l == 3)
{
world.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
}
}
}
/**
* If this returns true, then comparators facing away from this block will use the value from
* getComparatorInputOverride instead of the actual redstone signal strength.
*/
public boolean hasComparatorInputOverride()
{
return true;
}
/**
* If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
* strength when this block inputs to a comparator.
*/
public int getComparatorInputOverride(World world, int x, int y, int z, int direction)
{
return Container.calcRedstoneFromInventory((IInventory)world.getTileEntity(x, y, z));
}
/**
* Gets an item for the block being called on. Args: world, x, y, z
*/
@SideOnly(Side.CLIENT)
public Item getItem(World world, int x, int y, int z)
{
return Item.getItemFromBlock(Blocks.furnace);
}
}