Just to get me started in Java, I'm trying to make a golden crafting table. I've successfully created the craftable and placeable block but can't get the crafting gui to open. I've searched around the forum but all I can find are people that want to have a 3x6 crafting table or ones with different recipes and other things that are over my head. All I've learned is that I need the block file, the mod_block file, a new guicrafting file, and a new container file. Help?
Go to the canInteractWith method in your container class and make it return true instead of the code that is already there. The code that is currently there checks if the block at the position of the TileEntity is a workbench; if it isn't then it doesn't open the gui.
Rollback Post to RevisionRollBack
“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
Okay so I made a stupid and thought I had to copy Container.java not ContainerWorkbench.java. Now that I've done that my crafting table works but only if I right-click it several times rapidly. Help?
package net.minecraft.src;
import java.util.Random;
public class BlockGoldTable extends Block
{
private int topTexture = ModLoader.addOverride("/terrain.png","/GoldTable1.png");
private int side1Texture = ModLoader.addOverride("/terrain.png","/GoldTable2.png");
private int side2Texture = ModLoader.addOverride("/terrain.png","/GoldTable3.png");
protected BlockGoldTable(int i, int j)
{
super(i,j,Material.wood);
}
public int getBlockTextureFromSide(int side)
{
if (side == 1)
{
return topTexture;
}
if (side == 0)
{
return Block.planks.getBlockTextureFromSide(0);
}
if (side == 3)
{
return side2Texture;
}
if (side == 5)
{
return side2Texture;
}
else
{
return side1Texture;
}
}
public int idDropped(int i, Random random)
{
return Block.dirt.blockID; //Item.slimeBall.shiftedIndex;
}
public int quantityDropped(Random random)
{
return 1;
}
public boolean func_71903_a(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (par1World.isRemote)
{
return true;
}
else
{
par5EntityPlayer.displayWorkbenchGUI(par2, par3, par4);
return true;
}
}
}
mod_GolTabBlock.java:
package net.minecraft.src;
import java.util.Random;
public class mod_GolTabBlock extends BaseMod
{
public static final Block goldTable = new BlockGoldTable(251,0).setHardness(2.0F).setBlockName("goldtable");
public mod_GolTabBlock()
{
ModLoader.registerBlock(goldTable);
ModLoader.addName(goldTable,"Gold-Trim Crafting Table");
ModLoader.addRecipe(new ItemStack(goldTable, 3), new Object[]{
"#", '#', Block.dirt //"BBB", "CCC", "SSS", 'B', Item.brick, 'C', Block.cobblestone, 'S', Block.sandStone
});
}
public String getVersion()
{
return "3.14159265";
}
public void load()
{
}
}
ConatinerGold.java:
package net.minecraft.src;
import java.util.List;
public class ContainerGold extends Container
{
/** The crafting matrix inventory (3x3). */
public InventoryCrafting craftMatrix;
public IInventory craftResult;
private World worldObj;
private int posX;
private int posY;
private int posZ;
public ContainerGold(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
craftMatrix = new InventoryCrafting(this, 3, 3);
craftResult = new InventoryCraftResult();
worldObj = par2World;
posX = par3;
posY = par4;
posZ = par5;
func_75146_a(new SlotCrafting(par1InventoryPlayer.player, craftMatrix, craftResult, 0, 124, 35));
for (int i = 0; i < 3; i++)
{
for (int l = 0; l < 3; l++)
{
func_75146_a(new Slot(craftMatrix, l + i * 3, 30 + l * 18, 17 + i * 18));
}
}
for (int j = 0; j < 3; j++)
{
for (int i1 = 0; i1 < 9; i1++)
{
func_75146_a(new Slot(par1InventoryPlayer, i1 + j * 9 + 9, 8 + i1 * 18, 84 + j * 18));
}
}
for (int k = 0; k < 9; k++)
{
func_75146_a(new Slot(par1InventoryPlayer, k, 8 + k * 18, 142));
}
onCraftMatrixChanged(craftMatrix);
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory par1IInventory)
{
craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftMatrix));
}
/**
* Callback for when the crafting gui is closed.
*/
public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
{
super.onCraftGuiClosed(par1EntityPlayer);
if (worldObj.isRemote)
{
return;
}
for (int i = 0; i < 9; i++)
{
ItemStack itemstack = craftMatrix.getStackInSlotOnClosing(i);
if (itemstack != null)
{
par1EntityPlayer.dropPlayerItem(itemstack);
}
}
}
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
//if (worldObj.getBlockId(posX, posY, posZ) != Block.workbench.blockID)
//{
//return false;
//}
return par1EntityPlayer.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64D;
}
/**
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
*/
public ItemStack transferStackInSlot(int par1)
{
ItemStack itemstack = null;
Slot slot = (Slot)inventorySlots.get(par1);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (par1 == 0)
{
if (!mergeItemStack(itemstack1, 10, 46, true))
{
return null;
}
slot.func_75220_a(itemstack1, itemstack);
}
else if (par1 >= 10 && par1 < 37)
{
if (!mergeItemStack(itemstack1, 37, 46, false))
{
return null;
}
}
else if (par1 >= 37 && par1 < 46)
{
if (!mergeItemStack(itemstack1, 10, 37, false))
{
return null;
}
}
else if (!mergeItemStack(itemstack1, 10, 46, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack(null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(itemstack1);
}
return itemstack;
}
}
GuiCraftingGold.java:
package net.minecraft.src;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
public class GuiCraftingGold extends GuiContainer
{
public GuiCraftingGold(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
super(new ContainerWorkbench(par1InventoryPlayer, par2World, par3, par4, par5));
}
/**
* Draw the foreground layer for the GuiContainer (everythin in front of the items)
*/
protected void drawGuiContainerForegroundLayer()
{
fontRenderer.drawString(StatCollector.translateToLocal("container.crafting"), 28, 6, 0x404040);
fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
int i = mc.renderEngine.getTexture("/craftinggold.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(i);
int j = (width - xSize) / 2;
int k = (height - ySize) / 2;
drawTexturedModalRect(j, k, 0, 0, xSize, ySize);
}
}
The issue is that canInteractWith must return true, and the getDistanceSq thing you've got going on probably isn't always returning true. The code I've given you will always return true if the block at those coordinates is in fact the block it's supposed to be.
Still not working. The arm moves showing that it ativates correctly but the gui doesn't come up unless I use the original crafting table first, and when it does it's the original .png instead of my custom one. The code you gave me did make the gui come up sooner though.
Just to get me started in Java, I'm trying to make a golden crafting table. I've successfully created the craftable and placeable block but can't get the crafting gui to open. I've searched around the forum but all I can find are people that want to have a 3x6 crafting table or ones with different recipes and other things that are over my head. All I've learned is that I need the block file, the mod_block file, a new guicrafting file, and a new container file. Help?
I changed both things that you said to. The gui comes up faster and shows my survival inventory but still isn't the right .png and is kinda click-intensive to activate.
I changed both things that you said to. The gui comes up faster and shows my survival inventory but still isn't the right .png and is kinda click-intensive to activate.
If it's the wrong gui, you probably didnt do what he said. he meant this:
If it's the wrong gui, you probably didnt do what he said. he meant this:
Did you do THAT ^^^^^ ?
I thought I did. I didn't. Now the gui comes up with the players inventory :DDDD but the cursor doesn't appear and if you figure out where the mouse is and pick up a block it disappears forever. Little bit more help?
together they are powerful beyond imagination."
public abstract boolean canInteractWith(EntityPlayer entityplayer);
I copied the 1.3.1 container and guicrafting files and tried renaming things to work with my workbench and can't clear the errors.
That's what he's talking about.
No, I copied the entire code from the original Container.java and that code is nowhere in it. This is all that's under that canInteractWith:
mod_GolTabBlock.java:
ConatinerGold.java:
GuiCraftingGold.java:
...with...
The issue is that canInteractWith must return true, and the getDistanceSq thing you've got going on probably isn't always returning true. The code I've given you will always return true if the block at those coordinates is in fact the block it's supposed to be.
Your GUI is also still calling for ContainerWorkbench.
minecraft-pg5?
what is that?
I changed both things that you said to. The gui comes up faster and shows my survival inventory but still isn't the right .png and is kinda click-intensive to activate.
If it's the wrong gui, you probably didnt do what he said. he meant this:
Did you do THAT ^^^^^ ?
I thought I did. I didn't. Now the gui comes up with the players inventory :DDDD but the cursor doesn't appear and if you figure out where the mouse is and pick up a block it disappears forever. Little bit more help?
Does all that happen?