- 7
- 0
Здравствуйте.
Суть вопроса: есть блок-верстак (9х9), TileEntity, GUI, Container, в общем вроде бы всё есть. И GUI открывается, и предметы в слоты кладутся (верстак их хранит, пока не заберёшь), но вот с самим крафтом проблема. Сделал тестовый крафт, из 81 камня получается блок realminium_ore, а по факту блок можно скрафтить тогда, когда верстак пуст (т.е. из ничего). Можете подсказать,в чём тут проблема?
P.S.: Исходный код верстака и всего к нему относящегося не мой. Проблему с мгновенным закрытием GUI и последующим крашем решил, а тут уже не знаю как.
1)Главный класс:
2)Блок-Верстак:
3)TileEntity:
4)Container:
5)GUI:
6)Вроде как менеджер крафтов:
7)W_9x9_ShapedRecipe:
8)Inventory_9x9_W:
9)Inventory_9x9_W_Result:
Вроде бы всё (хотя, наверняка, минимум половина из этого не понадобится).
Суть вопроса: есть блок-верстак (9х9), TileEntity, GUI, Container, в общем вроде бы всё есть. И GUI открывается, и предметы в слоты кладутся (верстак их хранит, пока не заберёшь), но вот с самим крафтом проблема. Сделал тестовый крафт, из 81 камня получается блок realminium_ore, а по факту блок можно скрафтить тогда, когда верстак пуст (т.е. из ничего). Можете подсказать,в чём тут проблема?
P.S.: Исходный код верстака и всего к нему относящегося не мой. Проблему с мгновенным закрытием GUI и последующим крашем решил, а тут уже не знаю как.
1)Главный класс:
Java:
package ru.ds_mods.realmine;
import cpw.mods.fml.client.registry.RenderingRegistry;
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.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.util.EnumHelper;
import ru.ds_mods.realmine.armor.Botts;
import ru.ds_mods.realmine.armor.Chestplate;
import ru.ds_mods.realmine.armor.Helmet;
import ru.ds_mods.realmine.armor.Pants;
import ru.ds_mods.realmine.blocks.Block_9x9_W;
import ru.ds_mods.realmine.crafting.W_9x9_Manager;
import ru.ds_mods.realmine.gui.Gui_Handler;
import ru.ds_mods.realmine.tile.TileEntity_9x9_W;
import ru.ds_mods.realmine.tile.Tile_9x9_W;
@Mod (modid = "realmine", name="Realmine Mod", version = "1.0")
public class Sky_Core {
@Mod.Instance
public static Sky_Core instance;
public static Block realminium_ore;
public static Item realminium;
public static Block w_9x9;
public static Item realminium_pickaxe;
public static Item helmetModel;
public static Item chestplateModel;
public static Item pantsModel;
public static Item bottsModel;
@SidedProxy(clientSide = "ru.ds_mods.realmine.ClientProxy", serverSide = "ru.ds_mods.realmine.CommonProxy")
public static CommonProxy proxy;
@EventHandler
public void preLoad(FMLPreInitializationEvent event)
{
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new Gui_Handler());
GameRegistry.registerTileEntity(Tile_9x9_W.class, "tile_9x9_w");
realminium_ore = new Realmit_Ore();
GameRegistry.registerBlock(realminium_ore, "realminium_ore");
w_9x9 = new Block_9x9_W();
GameRegistry.registerBlock(w_9x9, "w_9x9");
GameRegistry.registerTileEntity(TileEntity_9x9_W.class, "tile_entity_9x9_w");
realminium = new Realmit().setUnlocalizedName("realminium");
GameRegistry.registerItem(realminium, "realminium");
helmetModel = new Helmet(0, 0).setUnlocalizedName("helmetModel");
GameRegistry.registerItem(helmetModel, "Helmet");
chestplateModel = new Chestplate(0, 1).setUnlocalizedName("chestplateModel");
GameRegistry.registerItem(chestplateModel, "Chestplate");
pantsModel = new Pants(0, 2).setUnlocalizedName("pantsModel");
GameRegistry.registerItem(pantsModel, "pantsModel");
bottsModel = new Botts(0, 3).setUnlocalizedName("bottsModel");
GameRegistry.registerItem(bottsModel, "bottsModel");
W_9x9_Manager.getInstance().addRecipe(new ItemStack(Sky_Core.realminium_ore, 1), new Object[] { "RRRRRRRRR", "RRRRRRRRR", "RRRRRRRRR", "RRRRRRRRR", "RRRRRRRRR", "RRRRRRRRR", "RRRRRRRRR", "RRRRRRRRR", "RRRRRRRRR",
Character.valueOf('R'), new ItemStack(Blocks.stone, 1) });
}
public static final ToolMaterial REALMINIUM = EnumHelper.addToolMaterial("REALMINIUM", 3, -1, 21.0F, 5.0F, 1);
public static ArmorMaterial REALMINIUM_ARMOR = EnumHelper.addArmorMaterial("REALMINIUM_ARMOR", 0, new int[] {5, 8, 7, 4}, 10);
public static CreativeTabs tabRealm = new TabRealmine("12");
}
2)Блок-Верстак:
Java:
package ru.ds_mods.realmine.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import ru.ds_mods.realmine.Sky_Core;
import ru.ds_mods.realmine.tile.TileEntity_9x9_W;
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.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class Block_9x9_W extends BlockContainer
{
private static IIcon top;
private static IIcon sides;
private static IIcon bottom;
private Random randy = new Random();
public Block_9x9_W()
{
super(Material.iron);
setStepSound(Block.soundTypeGlass);
setHardness(50.0F);
setResistance(2000.0F);
setBlockName("w_9x9_crafting");
setHarvestLevel("pickaxe", 3);
setCreativeTab(Sky_Core.tabRealm);
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister)
{
top = iconRegister.registerIcon("realmine:9x9_crafting_top");
sides = iconRegister.registerIcon("realmine:9x9_crafting_side");
bottom = iconRegister.registerIcon("realmine:9x9_crafting_bottom");
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata)
{
if (side == 0) {
return bottom;
}
if (side == 1) {
return top;
}
return sides;
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
player.openGui(Sky_Core.instance, 1, world, x, y, z);
return true;
}
public TileEntity createNewTileEntity(World world, int meta)
{
return new TileEntity_9x9_W();
}
public void breakBlock(World world, int x, int y, int z, Block block, int wut)
{
TileEntity_9x9_W craft = (TileEntity_9x9_W)world.getTileEntity(x, y, z);
if (craft != null) {
for (int i = 1; i < 82; i++)
{
ItemStack itemstack = craft.getStackInSlot(i);
if (itemstack != null)
{
float f = this.randy.nextFloat() * 0.8F + 0.1F;
float f1 = this.randy.nextFloat() * 0.8F + 0.1F;
float f2 = this.randy.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int j1 = this.randy.nextInt(21) + 10;
if (j1 > itemstack.stackSize) {
j1 = itemstack.stackSize;
}
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(world, x + f, y + f1, 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 = ((float)this.randy.nextGaussian() * f3);
entityitem.motionY = ((float)this.randy.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = ((float)this.randy.nextGaussian() * f3);
world.spawnEntityInWorld(entityitem);
}
}
world.func_147453_f(x, y, z, block);
}
}
super.breakBlock(world, x, y, z, block, wut);
}
}
3)TileEntity:
Java:
package ru.ds_mods.realmine.tile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TileEntity_9x9_W extends Tile_9x9_W
implements IInventory, ISidedInventory
{
private ItemStack result;
private ItemStack[] matrix = new ItemStack[81];
public boolean canUpdate()
{
return false;
}
public void readCustomNBT(NBTTagCompound tag)
{
this.result = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Result"));
for (int x = 0; x < this.matrix.length; x++) {
this.matrix[x] = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Craft" + x));
}
}
public void writeCustomNBT(NBTTagCompound tag)
{
if (this.result != null)
{
NBTTagCompound produce = new NBTTagCompound();
this.result.writeToNBT(produce);
tag.setTag("Result", produce);
}
else
{
tag.removeTag("Result");
}
for (int x = 0; x < this.matrix.length; x++) {
if (this.matrix[x] != null)
{
NBTTagCompound craft = new NBTTagCompound();
this.matrix[x].writeToNBT(craft);
tag.setTag("Craft" + x, craft);
}
else
{
tag.removeTag("Craft" + x);
}
}
}
public int getSizeInventory()
{
return 82;
}
public ItemStack getStackInSlot(int slot)
{
if (slot == 0) {
return this.result;
}
if (slot <= this.matrix.length) {
return this.matrix[(slot - 1)];
}
return null;
}
public ItemStack decrStackSize(int slot, int decrement)
{
if (slot == 0)
{
if (this.result != null)
{
for (int x = 1; x <= this.matrix.length; x++) {
decrStackSize(x, 1);
}
if (this.result.stackSize <= decrement)
{
ItemStack craft = this.result;
this.result = null;
return craft;
}
ItemStack split = this.result.splitStack(decrement);
if (this.result.stackSize <= 0) {
this.result = null;
}
return split;
}
return null;
}
if ((slot <= this.matrix.length) &&
(this.matrix[(slot - 1)] != null))
{
if (this.matrix[(slot - 1)].stackSize <= decrement)
{
ItemStack ingredient = this.matrix[(slot - 1)];
this.matrix[(slot - 1)] = null;
return ingredient;
}
ItemStack split = this.matrix[(slot - 1)].splitStack(decrement);
if (this.matrix[(slot - 1)].stackSize <= 0) {
this.matrix[(slot - 1)] = null;
}
return split;
}
return null;
}
public void openInventory() {}
public void closeInventory() {}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return true;
}
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
return false;
}
public int getInventoryStackLimit()
{
return 64;
}
public void setInventorySlotContents(int slot, ItemStack stack)
{
if (slot == 0) {
this.result = stack;
} else if (slot <= this.matrix.length) {
this.matrix[(slot - 1)] = stack;
}
}
public ItemStack getStackInSlotOnClosing(int slot)
{
return null;
}
public String getInventoryName()
{
return "container.dire";
}
public boolean hasCustomInventoryName()
{
return false;
}
public int[] getAccessibleSlotsFromSide(int side)
{
return new int[0];
}
public boolean canInsertItem(int slot, ItemStack item, int side)
{
return false;
}
public boolean canExtractItem(int slot, ItemStack item, int side)
{
return false;
}
}
4)Container:
Java:
package ru.ds_mods.realmine.gui;
import ru.ds_mods.realmine.crafting.W_9x9_Manager;
import ru.ds_mods.realmine.tile.TileEntity_9x9_W;
import ru.ds_mods.realmine.tile.inventory.Inventory_9x9_W;
import ru.ds_mods.realmine.tile.inventory.Inventory_9x9_W_Result;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class Container_9x9_W extends Container
{
public InventoryCrafting craftMatrix;
public IInventory craftResult;
private World worldObj;
private int posX;
private int posY;
private int posZ;
public Container_9x9_W(InventoryPlayer player, World world, int x, int y, int z, TileEntity_9x9_W table)
{
this.worldObj = world;
this.posX = x;
this.posY = y;
this.posZ = z;
this.craftMatrix = new Inventory_9x9_W(this, table);
this.craftResult = new Inventory_9x9_W_Result(table);
addSlotToContainer(new SlotCrafting(player.player, this.craftMatrix, this.craftResult, 0, 210, 80));
for (int wy = 0; wy < 9; wy++) {
for (int ex = 0; ex < 9; ex++) {
addSlotToContainer(new Slot(this.craftMatrix, ex + wy * 9, 12 + ex * 18, 8 + wy * 18));
}
}
for (int wy = 0; wy < 3; wy++) {
for (int ex = 0; ex < 9; ex++) {
addSlotToContainer(new Slot(player, ex + wy * 9 + 9, 39 + ex * 18, 174 + wy * 18));
}
}
for (int ex = 0; ex < 9; ex++) {
addSlotToContainer(new Slot(player, ex, 39 + ex * 18, 232));
}
onCraftMatrixChanged(this.craftMatrix);
}
public void onCraftMatrixChanged(IInventory matrix)
{
this.craftResult.setInventorySlotContents(0, W_9x9_Manager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
}
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed(player);
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(slotNumber);
if ((slot != null) && (slot.getHasStack()))
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (slotNumber == 0)
{
if (!mergeItemStack(itemstack1, 82, 118, true)) {
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if ((slotNumber >= 82) && (slotNumber < 109))
{
if (!mergeItemStack(itemstack1, 109, 118, false)) {
return null;
}
}
else if ((slotNumber >= 109) && (slotNumber < 118))
{
if (!mergeItemStack(itemstack1, 82, 109, false)) {
return null;
}
}
else if (!mergeItemStack(itemstack1, 82, 118, false))
{
return null;
}
if (itemstack1.stackSize == 0) {
slot.putStack((ItemStack)null);
} else {
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize) {
return null;
}
slot.onPickupFromSlot(player, itemstack1);
}
return itemstack;
}
}
5)GUI:
Java:
package ru.ds_mods.realmine.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import ru.ds_mods.realmine.tile.TileEntity_9x9_W;
public class Gui_9x9_W extends GuiContainer
{
private static final ResourceLocation tex = new ResourceLocation("realmine:textures/gui/dire_crafting_gui.png");
public Gui_9x9_W(InventoryPlayer par1InventoryPlayer, World par2World, int x, int y, int z, TileEntity_9x9_W table)
{
super(new Container_9x9_W(par1InventoryPlayer, par2World, x, y, z, table));
this.ySize = 256;
this.xSize = 238;
}
protected void drawGuiContainerForegroundLayer(int i, int j) {}
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(tex);
int foo = (this.width - this.xSize) / 2;
int bar = (this.height - this.ySize) / 2;
drawTexturedModalRect(foo, bar, 0, 0, this.ySize, this.ySize);
}
}
6)Вроде как менеджер крафтов:
Java:
package ru.ds_mods.realmine.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class W_9x9_Manager {
private static final W_9x9_Manager instance1 = new W_9x9_Manager();
private List recipes = new ArrayList();
public static final W_9x9_Manager getInstance()
{
return instance1;
}
public W_9x9_ShapedRecipe addRecipe(ItemStack result, Object... recipe)
{
String s = "";
int i = 0;
int width = 0;
int height = 0;
if ((recipe[i] instanceof String[]))
{
String[] astring = (String[])(String[])recipe[(i++)];
for (int l = 0; l < astring.length; l++)
{
String s1 = astring[l];
height++;
width = s1.length();
s = s + s1;
}
}
else
{
while ((recipe[i] instanceof String))
{
String s2 = (String)recipe[(i++)];
height++;
width = s2.length();
s = s + s2;
}
}
for (HashMap hashmap1 = new HashMap(); i < recipe.length; i += 2)
{
Character character = (Character)recipe[i];
ItemStack itemstack1 = null;
if ((recipe[(i + 1)] instanceof Item)) {
itemstack1 = new ItemStack((Item)recipe[(i + 1)]);
} else if ((recipe[(i + 1)] instanceof Block)) {
itemstack1 = new ItemStack((Block)recipe[(i + 1)], 1, 32767);
} else if ((recipe[(i + 1)] instanceof ItemStack)) {
itemstack1 = (ItemStack)recipe[(i + 1)];
}
hashmap1.put(character, itemstack1);
}
ItemStack[] ingredients = new ItemStack[width * height];
HashMap hashmap1 = new HashMap();
for (int i1 = 0; i1 < width * height; i1++ )
{
char c0 = s.charAt(i1);
if (hashmap1.containsKey(Character.valueOf(c0))) {
ingredients[i1] = ((ItemStack)hashmap1.get(Character.valueOf(c0))).copy();
} else {
ingredients[i1] = null;
}}
W_9x9_ShapedRecipe shapedrecipes = new W_9x9_ShapedRecipe(width, height, ingredients, result);
this.recipes.add(shapedrecipes);
return shapedrecipes;
}
public ItemStack findMatchingRecipe(InventoryCrafting matrix, World world)
{
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
for (int j = 0; j < matrix.getSizeInventory(); j++)
{
ItemStack itemstack2 = matrix.getStackInSlot(j);
if (itemstack2 != null)
{
if (i == 0) {
itemstack = itemstack2;
}
if (i == 1) {
itemstack1 = itemstack2;
}
i++;
}
}
if ((i == 2) && (itemstack.getItem() == itemstack1.getItem()) && (itemstack.stackSize == 1) && (itemstack1.stackSize == 1) && (itemstack.getItem().isRepairable()))
{
Item item = itemstack.getItem();
int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay();
int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();
int l = j1 + k + item.getMaxDamage() * 5 / 100;
int i1 = item.getMaxDamage() - l;
if (i1 < 0) {
i1 = 0;
}
return new ItemStack(itemstack.getItem(), 1, i1);
}
for (int j = 0; j < this.recipes.size(); j++)
{
IRecipe irecipe = (IRecipe)this.recipes.get(j);
if (irecipe.matches(matrix, world)) {
return irecipe.getCraftingResult(matrix);
}
}
return null;
}
public List getRecipeList()
{
return this.recipes;
}
}
7)W_9x9_ShapedRecipe:
Java:
package ru.ds_mods.realmine.crafting;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class W_9x9_ShapedRecipe implements IRecipe
{
public final int recipeWidth;
public final int recipeHeight;
public final ItemStack[] recipeItems;
private ItemStack recipeOutput;
public W_9x9_ShapedRecipe(int width, int height, ItemStack[] ingredients, ItemStack result)
{
this.recipeWidth = width;
this.recipeHeight = height;
this.recipeItems = ingredients;
this.recipeOutput = result;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
public boolean matches(InventoryCrafting matrix, World world)
{
for (int i = 0; i <= 9 - this.recipeWidth; i++) {
for (int j = 0; j <= 9 - this.recipeHeight; j++)
{
if (checkMatch(matrix, i, j, true)) {
return true;
}
if (checkMatch(matrix, i, j, false)) {
return true;
}
}
}
return false;
}
private boolean checkMatch(InventoryCrafting matrix, int x, int y, boolean mirrored)
{
for (int k = 0; k < 9; k++) {
for (int l = 0; l < 9; l++)
{
int i1 = k - x;
int j1 = l - y;
ItemStack itemstack = null;
if ((i1 >= 0) && (j1 >= 0) && (i1 < this.recipeWidth) && (j1 < this.recipeHeight)) {
if (mirrored) {
itemstack = this.recipeItems[(this.recipeWidth - i1 - 1 + j1 * this.recipeWidth)];
} else {
itemstack = this.recipeItems[(i1 + j1 * this.recipeWidth)];
}
}
ItemStack itemstack1 = matrix.getStackInRowAndColumn(k, l);
if ((itemstack1 != null) || (itemstack != null))
{
if (((itemstack1 == null) && (itemstack != null)) || ((itemstack1 != null) && (itemstack == null))) {
return false;
}
if (itemstack.getItem() != itemstack1.getItem()) {
return false;
}
if ((itemstack.getItemDamage() != 32767) && (itemstack.getItemDamage() != itemstack1.getItemDamage())) {
return false;
}
if ((itemstack.hasTagCompound()) && (!ItemStack.areItemStackTagsEqual(itemstack, itemstack1))) {
return false;
}
}
}
}
return true;
}
public ItemStack getCraftingResult(InventoryCrafting p_77572_1_)
{
return getRecipeOutput().copy();
}
public int getRecipeSize()
{
return this.recipeWidth * this.recipeHeight;
}
}
8)Inventory_9x9_W:
Java:
package ru.ds_mods.realmine.tile.inventory;
import ru.ds_mods.realmine.tile.TileEntity_9x9_W;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
public class Inventory_9x9_W extends InventoryCrafting {
private TileEntity_9x9_W craft;
private Container container;
public Inventory_9x9_W(Container cont, TileEntity_9x9_W table)
{
super(cont, 9, 9);
this.craft = table;
this.container = cont;
}
public ItemStack getStackInSlot(int slot)
{
return slot >= getSizeInventory() ? null : this.craft.getStackInSlot(slot + 1);
}
public ItemStack getStackInRowAndColumn(int row, int column)
{
if ((row >= 0) && (row < 9))
{
int x = row + column * 9;
return getStackInSlot(x);
}
return null;
}
public ItemStack getStackInSlotOnClosing(int par1)
{
return null;
}
public ItemStack decrStackSize(int slot, int decrement)
{
ItemStack stack = this.craft.getStackInSlot(slot + 1);
if (stack != null)
{
if (stack.stackSize <= decrement)
{
ItemStack itemstack = stack.copy();
stack = null;
this.craft.setInventorySlotContents(slot + 1, null);
this.container.onCraftMatrixChanged(this);
return itemstack;
}
ItemStack itemstack = stack.splitStack(decrement);
if (stack.stackSize == 0) {
stack = null;
}
this.container.onCraftMatrixChanged(this);
return itemstack;
}
return null;
}
public void setInventorySlotContents(int slot, ItemStack itemstack)
{
this.craft.setInventorySlotContents(slot + 1, itemstack);
this.container.onCraftMatrixChanged(this);
}
}
9)Inventory_9x9_W_Result:
Java:
package ru.ds_mods.realmine.tile.inventory;
import ru.ds_mods.realmine.tile.TileEntity_9x9_W;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.item.ItemStack;
public class Inventory_9x9_W_Result extends InventoryCraftResult
{
private TileEntity_9x9_W craft;
public Inventory_9x9_W_Result(TileEntity_9x9_W table)
{
this.craft = table;
}
public ItemStack getStackInSlot(int par1)
{
return this.craft.getStackInSlot(0);
}
public ItemStack decrStackSize(int par1, int par2)
{
ItemStack stack = this.craft.getStackInSlot(0);
if (stack != null)
{
ItemStack itemstack = stack;
this.craft.setInventorySlotContents(0, null);
return itemstack;
}
return null;
}
public ItemStack getStackInSlotOnClosing(int par1)
{
return null;
}
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{
this.craft.setInventorySlotContents(0, par2ItemStack);
}
}
Вроде бы всё (хотя, наверняка, минимум половина из этого не понадобится).