Jump to content

[1.8]--Custom Crafting Table not Opening GUI


Recommended Posts

Hello, fellow forum adicts !

 

Soo... my custom crafting table is not working for some reason :/

 

The GUI wont open and the Console doesn't put out any information at all...

 

Here is my code:

 

The Block Class

package com.nikola.carbonmod.blocks;

import com.nikola.carbonmod.CarbonMod;
import com.nikola.carbonmod.container.ContainerIronForge;
import com.nikola.carbonmod.init.CarbonBlocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockWorkbench;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.internal.FMLNetworkHandler;

public class IronForge extends Block {

private static final String __OBFID = "CL_00000221";

public IronForge(Material materialIn) {
	super(materialIn);
	this.setHardness(3.0F);
	this.setResistance(15.0F);
	this.isBlockContainer = true;
}

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

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

public boolean onBlockActivated(World worldIn, int x, int y , int z, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (worldIn.isRemote && playerIn.isSneaking())
        {
            return true;
        }
        else
        {
        	FMLNetworkHandler.openGui(playerIn, CarbonMod.instance, CarbonBlocks.guiIDIronForge, worldIn, x, y, z);
            return true;
        }
    }

public static class InterfaceCraftingTable implements IInteractionObject
    {
        private final World world;
        private final BlockPos position;
        private static final String __OBFID = "CL_00002127";

        public InterfaceCraftingTable(World worldIn, BlockPos pos)
        {
            this.world = worldIn;
            this.position = pos;
        }

        public String getName()
        {
            return null;
        }

        public boolean hasCustomName()
        {
            return false;
        }

        public IChatComponent getDisplayName()
        {
            return new ChatComponentTranslation(CarbonBlocks.ironForge.getUnlocalizedName() + ".name", new Object[0]);
        }

        public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
        {
            return new ContainerIronForge(playerInventory, this.world, this.position);
        }

        public String getGuiID()
        {
            return "carbonmod:ironForge";
        }
    }
}

 

The Container for The Block

package com.nikola.carbonmod.container;

import com.nikola.carbonmod.crafting.IronForgeCraftingManager;
import com.nikola.carbonmod.init.CarbonBlocks;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
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 net.minecraft.util.BlockPos;
import net.minecraft.world.World;

public class ContainerIronForge extends Container {

public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
public IInventory craftResult = new InventoryCraftResult();;
private World worldObj;
private BlockPos field_178145_h;
private static final String __OBFID = "CL_00001744";

public ContainerIronForge(InventoryPlayer invPlayer, World worldIn, BlockPos p_i45800_3_) {

	this.worldObj = worldIn;
	this.field_178145_h = p_i45800_3_;
	this.addSlotToContainer(new SlotCrafting(invPlayer.player, this.craftMatrix, this.craftResult, 0, 124, 35));
	int i;
        int j;

	for (i = 0; i < 3; ++i)
        {
            for (j = 0; j < 3; ++j)
            {
                this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18));
            }
        }

        for (i = 0; i < 3; ++i)
        {
            for (j = 0; j < 9; ++j)
            {
                this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
            }
        }

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

	this.onCraftMatrixChanged(this.craftMatrix);
}

//GuiHandlerConstructor
public ContainerIronForge(InventoryPlayer invPlayer, World world, int x, int y, int z) {
}

public void onCraftMatrixChanged(IInventory inventoryIn) {
        //this.craftResult.setInventorySlotContents(0, IronForgeCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
    }

public void onContainerClosed(EntityPlayer playerIn) {
	super.onContainerClosed(playerIn);

	if (!this.worldObj.isRemote) {
		for (int i = 0; i < 9; ++i) {
			ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);

			if (itemstack != null) {
				playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
			}
		}
	}
}

@Override
public boolean canInteractWith(EntityPlayer playerIn)
    {
        return this.worldObj.getBlockState(this.field_178145_h).getBlock() != CarbonBlocks.ironForge ? false : playerIn.getDistanceSq((double)this.field_178145_h.getX() + 0.5D, (double)this.field_178145_h.getY() + 0.5D, (double)this.field_178145_h.getZ() + 0.5D) <= 64.0D;
    }

public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
	ItemStack itemstack = null;
	Slot slot = (Slot) this.inventorySlots.get(index);

	if (slot != null && slot.getHasStack()) {
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();

		if (index == 0) {
			if (!this.mergeItemStack(itemstack1, 10, 46, true)) {
				return null;
			}

			slot.onSlotChange(itemstack1, itemstack);
		} else if (index >= 10 && index < 37) {
			if (!this.mergeItemStack(itemstack1, 37, 46, false)) {
				return null;
			}
		} else if (index >= 37 && index < 46) {
			if (!this.mergeItemStack(itemstack1, 10, 37, false)) {
				return null;
			}
		} else if (!this.mergeItemStack(itemstack1, 10, 46, false)) {
			return null;
		}

		if (itemstack1.stackSize == 0) {
			slot.putStack((ItemStack) null);
		} else {
			slot.onSlotChanged();
		}

		if (itemstack1.stackSize == itemstack.stackSize) {
			return null;
		}

		slot.onPickupFromSlot(playerIn, itemstack1);
	}

	return itemstack;
}

@Override
public boolean canMergeSlot(ItemStack p_94530_1_, Slot p_94530_2_) {
	return p_94530_2_.inventory != this.craftResult && super.canMergeSlot(p_94530_1_, p_94530_2_);
}
}

 

The Gui Handler

package com.nikola.carbonmod.gui;

import com.nikola.carbonmod.container.ContainerIronForge;
import com.nikola.carbonmod.init.CarbonBlocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,	int x, int y, int z) {
	TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));

	if(ID == CarbonBlocks.guiIDIronForge) {
		return ID == CarbonBlocks.guiIDIronForge && world.getBlockState(new BlockPos(x, y, z)) == CarbonBlocks.ironForge ? new ContainerIronForge(player.inventory, world, x, y, z) : null;
	}
	return entity;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { 

	TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));

	if(ID == CarbonBlocks.guiIDIronForge) {
		return ID == CarbonBlocks.guiIDIronForge && world.getBlockState(new BlockPos(x, y, z)) == CarbonBlocks.ironForge ? new GuiIronForge(player.inventory, world, x, y, z) : null;
	}
	return entity;
}
}

 

and The GUI for The Block

package com.nikola.carbonmod.gui;

import com.nikola.carbonmod.container.ContainerIronForge;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerWorkbench;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiIronForge extends GuiContainer
{
private static final ResourceLocation ironForgeGuiTextures = new ResourceLocation("textures/gui/container/ironForge.png");
    private static final String __OBFID = "CL_00000750";

    public GuiIronForge(InventoryPlayer playerInv, World worldIn, int x, int y, int z)
    {
        this(playerInv, worldIn, BlockPos.ORIGIN);
    }

    public GuiIronForge(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition)
    {
        super(new ContainerIronForge(playerInv, worldIn, blockPosition));
    }

    public void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
    {
        this.fontRendererObj.drawString(I18n.format("container.crafting", new Object[0]), 28, 6, 4210752);
        this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
    }

    public void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
    {
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(ironForgeGuiTextures);
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
    }
}

To Craft, or not to Craft. That is the question.

Link to comment
Share on other sites

Your onBlockActivated methode has not the right arguments:

 

    onBlockActivated(World worldIn, int x, int y , int z, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)

 

Right is:

 

  onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)

Sorry if there are mistakes in my english

Link to comment
Share on other sites

I really want to learn Java :) but can't fint the right tutorial. Any suggestions ?

 

I recommend the following book: Java in Easy Steps http://www.amazon.com/Java-Easy-Steps-Fully-Updated/dp/1840784431

 

What I like about it is that it covers all the key topics but isn't as boring or scary as many coding books. It is a nice quick read and you'll learn a lot.

 

Also, I believe coding is something you need to learn from an actual book. Video tutorials have a set pace that may not suit where you're at in your learning. Also, people tend to skip ahead in videos and miss some of the key early concepts, whereas a book will lay it out for you in very specific way to build up your knowledge.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

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

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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