Jump to content

Recommended Posts

Posted

Hello! I've been trying all day and I just can't figure out how to do this. I want to make a "Runetable" that allows you to put in a tool and a rune and in return, get a special version of that tool. What i'm having trouble with is the detecting what items are in the slots as for some reason they always seem null. I'm not sure if I should detect the items in the slots and have a new tool appear in the other slot or use the crafting matrix. Although I havn't found any helpful tutorials for using the crafting matrix :( so I don't know how to use it. I've looked at the Crafting Table's container and I still just need some help. Which should I use and can I have some guidance on how to do it? Here's what I have so far:

 

TileEntityRunetable.java

package tileentities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import skillcraft.items.ItemInfo;
import skillcraft.items.ItemRuneJump;
import skillcraft.items.Items;

public class TileEntityRunetable extends TileEntity implements IInventory
{

private ItemStack[] items;

public TileEntityRunetable()
{
	items = new ItemStack[2];
}

@Override
public int getSizeInventory()
{
	return items.length;
}

@Override
public ItemStack getStackInSlot(int i)
{
	return items[i];
}

@Override
public ItemStack decrStackSize(int i, int count)
{
	ItemStack itemstack = getStackInSlot(i);

	if (itemstack != null)
	{
		if (itemstack.stackSize <= count)
		{
			setInventorySlotContents(i, null);
		} 
		else
		{
			itemstack = itemstack.splitStack(count);
			onInventoryChanged();
		}
	}

	return itemstack;
}

@Override
public ItemStack getStackInSlotOnClosing(int i)
{
	ItemStack item = getStackInSlot(i);
	setInventorySlotContents(i, null);
	return item;
}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
	items[i] = itemstack;
	System.out.println(itemstack.itemID);

	if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
	{
		itemstack.stackSize = getInventoryStackLimit();
	}

	onInventoryChanged();
}

@Override
public String getInvName()
{
	return "InventoryRunetable";
}

@Override
public boolean isInvNameLocalized()
{
	return false;
}

@Override
public int getInventoryStackLimit()
{
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
	return entityplayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64;
}

@Override
public void openChest(){}

@Override
public void closeChest(){}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
	return false;
}

@Override
public void writeToNBT(NBTTagCompound compound)
{
	super.writeToNBT(compound);

	NBTTagList items = new NBTTagList();

	for (int i = 0; i < getSizeInventory(); i++)
	{
		ItemStack stack = getStackInSlot(i);

		if (stack != null)
		{
			NBTTagCompound item = new NBTTagCompound();
			item.setByte("Slot", (byte)i);
			stack.writeToNBT(item);
			items.appendTag(item);
		}
	}

	compound.setTag("Items", items);
}

@Override
public void readFromNBT(NBTTagCompound compound)
{
	super.readFromNBT(compound);

	NBTTagList items = compound.getTagList("Items");

	for (int i = 0; i < items.tagCount(); i ++)
	{
		 NBTTagCompound item = (NBTTagCompound)items.tagAt(i);

		 int slot = item.getByte("Slot");

		 if (slot >= 0 && slot < getSizeInventory())
		 {
			 setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
		 }
	}
}

public void checkRecipie(Slot rune, Slot item)
{
	if (rune.getStack().itemID == ItemInfo.RUNE_JUMP_ID)
		System.out.println("always crashes...");

}

}

 

BlockRuneTable.java

package skillcraft.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import skillcraft.SkillCraft;
import skillcraft.client.CreativeTab;
import skillcraft.items.ItemInfo;
import tileentities.TileEntityRunetable;
import cpw.mods.fml.common.network.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockRuneTable extends BlockContainer
{

public BlockRuneTable(int id)
{
	super(id, Material.rock);

	setCreativeTab(CreativeTab.skillcraftTab);
	setHardness(2F);
	setStepSound(Block.soundStoneFootstep);
	setUnlocalizedName(BlockInfo.RUNETABLE_UNLOCALIZED_NAME);
}

@SideOnly(Side.CLIENT)
private Icon topIcon;
@SideOnly(Side.CLIENT)
private Icon botIcon;
@SideOnly(Side.CLIENT)
private Icon sideIcon;

@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister register)
{
	topIcon = register.registerIcon(BlockInfo.TEXTURE_LOCATION + ":" + BlockInfo.RUNETABLE_TOP);
	botIcon = register.registerIcon(BlockInfo.TEXTURE_LOCATION + ":" + BlockInfo.RUNETABLE_BOT);
	sideIcon = register.registerIcon(BlockInfo.TEXTURE_LOCATION + ":" + BlockInfo.RUNETABLE_SIDE);
}

@SideOnly(Side.CLIENT)
@Override
public Icon getIcon(int side, int meta)
{
	switch (side)
	{
	case 0:
		return botIcon;
	case 1:
		return topIcon;
	default:
		return sideIcon;
	}

}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
	if (!world.isRemote)
	{
		FMLNetworkHandler.openGui(player, SkillCraft.instance, 0, world, x, y, z);
	}

	return true;
}

@Override
public TileEntity createNewTileEntity(World world)
{
	return new TileEntityRunetable();
}
}

 

ContainerRunetable.java

package skillcraft.client.interfaces;

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.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import skillcraft.client.interfaces.slots.SlotAddRune;
import skillcraft.client.interfaces.slots.SlotNewItem;
import skillcraft.client.interfaces.slots.SlotOldItem;
import tileentities.TileEntityRunetable;

public class ContainerRunetable extends Container
{

private TileEntityRunetable runetable;

public InventoryCrafting craftMatrix = new InventoryCrafting(this, 1, 2);
    public IInventory craftResult = new InventoryCraftResult();

public ContainerRunetable(InventoryPlayer invPlayer, TileEntityRunetable runetable)
{
	this.runetable = runetable;

	for(int x = 0; x < 9; x++)
	{
		addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 142));
	}

	for(int y = 0; y < 3; y++)
	{
		for(int x = 0; x < 9; x++)
		{
			addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18));
		}
	}

	addSlotToContainer(new SlotOldItem(invPlayer, 37, 53, 28));
	addSlotToContainer(new SlotAddRune(invPlayer, 38, 53, 46));

	addSlotToContainer(new SlotNewItem(invPlayer, 0, 124, 35));
}

@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
	return runetable.isUseableByPlayer(entityplayer);
}

public TileEntityRunetable getRunetable()
{
	return runetable;
}

    @Override
    public ItemStack slotClick(int slot, int clickType, int clickMeta, EntityPlayer player)
    {
            if(slot <= 38 && slot > -1)
                    updateCrafting();
            ItemStack stack = super.slotClick(slot, clickType, clickMeta, player);
            return stack;
    }
    
public void updateCrafting()
{
	runetable.checkRecipie(getSlot(0), getSlot(1));
}

}

 

I attached a picture of the GUI i've made along with the items that should be used together in the right slots in case that helps. Also, I'm new to the forums so if I did something wrong, sorry i'll try to fix it :)

 

width=800 height=423http://s27.postimg.org/mtb2xjz77/2014_01_27_22_08_12.png[/img]

 

Thank you!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.