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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
    • The link to your log does not work, it says it is forbidden, Error, this is a private paste or is pending moderation.
  • Topics

×
×
  • Create New...

Important Information

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