Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey there and good evening fellow devs.

 

I created a custom Workbench with a custom 3D-Model (created using BlockBench)
I managed to implement the block in the game, I can place it, break it, just like a normal block, however, I encountered two problems I just can't find a solution for.

The first, and minor problem is, that it requires no breaking time, so as soon as you left-click the block, it breaks immediately. How can I set the breaking time of a block? (If that's what you call it. It should have the same time you need for breaking a normal workbench)

The second, and kinda big problem is, that the GUI won't show up when I right-click it. When I click often enough, I do manage to open it, but it pops up for only a millisecond or so, before it closes again. How can I make the custom workbench to actually let me craft stuff?

 

Here is my class for the Custom workbench:

package com.korlimann.sushimod.blocks;

import com.korlimann.sushimod.Main;
import com.korlimann.sushimod.init.ModBlocks;
import com.korlimann.sushimod.init.ModItems;
import com.korlimann.sushimod.util.IHasModel;

import net.minecraft.block.BlockWorkbench;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
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.ContainerWorkbench;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.stats.StatList;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.World;

public class BlockBaseCraftingTable extends BlockWorkbench implements IHasModel {
	
	public String name;
	
	public BlockBaseCraftingTable(String name) {
		this.name = name;
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(Main.korlissushicraft);
		
		ModBlocks.BLOCKS.add(this);
		ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
	}
	
	/**
     * Called when the block is right clicked by a player.
     */
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (worldIn.isRemote)
        {
            return true;
        }
        else
        {
            playerIn.displayGui(new BlockWorkbench.InterfaceCraftingTable(worldIn, pos));
            playerIn.addStat(StatList.CRAFTING_TABLE_INTERACTION);
            return true;
        }
    }
    
	@Override
	public void registerModels() {
		Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");		
	}
    
    public static final AxisAlignedBB AABB = new AxisAlignedBB(0D,0,0.0625D,1D,0.125D,0.9375D);
    
    @Override
    public BlockRenderLayer getBlockLayer() {
        return BlockRenderLayer.CUTOUT;
    }
    
    @Override
    public boolean isOpaqueCube(IBlockState state) 
    {
        return false;
    }
    
    @Override
    public boolean isFullCube(IBlockState state) 
    {
        return false;
    }
    
    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) 
    {
        return AABB;
    }
}

 

If you need any additional code, tell me and I will send it as soon as possible. :) I don't know what will be needed, and I don't want to make this topic too long.

 

I hope anyone can help me with this. :D

Cheers and have a nice evening

Korlimann

in your constructor (or where you want :p), just add this and set it to 0

setHardness(0F);

and for the GUI maybe this might help you

FMLNetworkHandler.openGui(args);

 

normally that should fix all your issues :P

Greets Sir_titi

Always looking for new challenges, and happy to help the people where ever I can

  • Author
5 minutes ago, sir_titi said:

and for the GUI maybe this might help you


FMLNetworkHandler.openGui(args);

 

Where exactly do I need to put this line? Also into my constructor or into my onBlockActivated method? :3

no in your case in your onBlockActivated(args)

Always looking for new challenges, and happy to help the people where ever I can

  • Author
4 minutes ago, sir_titi said:

no in your case in your onBlockActivated(args)

Nope, does not work. :(

 

Does not even pop up for a millisecond anymore.

Edited by Korlimann

did you call this on server side cuss this should work :S

Always looking for new challenges, and happy to help the people where ever I can

did you make a class that implements "IGuiHandler"

Always looking for new challenges, and happy to help the people where ever I can

  • Author
1 minute ago, sir_titi said:

did you call this on server side cuss this should work :S

...what do you mean by "on the server side"? xD

 

Just started coding mods after years again and I kinda still need to get into it again.

 

How can I call it from the server side? :D

 

haha LOL :)

well pretty easy :P 

in your "onBlockActivated" you have a World param

well use that as follows

if (wereld.isRemote){//is client

}else{//is server

}

 

Always looking for new challenges, and happy to help the people where ever I can

  • Author
Just now, sir_titi said:

did you make a class that implements "IGuiHandler"

Nope. I guess I'll need this? xD

  • Author
Just now, sir_titi said:

haha LOL :)

well pretty easy :P 

in your "onBlockActivated" you have a World param

well use that as follows


if (wereld.isRemote){//is client

}else{//is server

}

 

I did it like this:

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (worldIn.isRemote)
        {
            return true;
        }
        else
        {
            FMLNetworkHandler.openGui(playerIn, Main.instance, Reference.GUI_KITCHENBOARD, worldIn, pos.getX(), pos.getY(), pos.getZ());
            playerIn.addStat(StatList.CRAFTING_TABLE_INTERACTION);
            return true;
        }
    }

I guess, according to what you wrote, I called it from the serverside. :D

well if you have a Gui that has a "container" yea you will need that.

wait a sec :P

public class R2S_GuiHandler implements IGuiHandler {
	private GameSettings sets;
	/**test
	public void onKeyInput(InputEvent.KeyInputEvent event, EntityPlayer speler, World wereld,int x, int y, int z) {
		if(ToetsenBinden.pong.isPressed())
			speler.openGui(R2S_UsefulBlocks.instance, 1, wereld, x, y, z);
	}				**/
	public enum GUIIDS{
		guiRadio;
	}
	
	public Object getClientGuiElement(int ID, EntityPlayer speler, World wereld,int x, int y, int z) {
		TileEntity tileentity = wereld.getTileEntity(new BlockPos(x, y, z));
	//	speler.getPersistentID();
		/**if(ToetsenBinden.inventaries.isPressed()){
			System.out.println("test bctGuihandler guiharnas");
		speler.openGui(R2S_UsefulBlocks.instance, Constante.guiHarnas, wereld, x, y, z);}				**/
		/*switch(GUIIDS.values()[ID]){
		case guiRadio:
			if(tileentity instanceof TERadio){
				return new GuiRadio(speler.inventory,(TERadio)tileentity);
			}
		}*/
		switch(ID){
		case Constante.guiRadio:
			if(tileentity instanceof TERadio){
				return new GuiRadio(speler.inventory,speler,(TERadio)tileentity,wereld,x,y,z);
			}
			break;
		case Constante.guiJukeBox:
			if(tileentity instanceof TEjukeBox){
				return new GuiJukeBox(speler.inventory,speler,(TEjukeBox)tileentity,wereld,x,y,z);
			}
			break;
		}
		throw new IllegalArgumentException("["+Constante.MODNAME+"] no Correct GUI ID : "+ID);
	}
	public Object getServerGuiElement(int ID, EntityPlayer speler, World wereld, int x, int y, int z) {
		TileEntity tileentity = wereld.getTileEntity(new BlockPos(x, y, z));
		//speler.getPersistentID();
		/**if (ToetsenBinden.inventaries.isPressed()){
			System.out.println("test bctGuihandler guiharnas");
		speler.openGui(R2S_UsefulBlocks.instance, Constante.guiHarnas, wereld, x, y, z);}							**/
		/*switch(GUIIDS.values()[ID]){
		case guiRadio:
			if(tileentity instanceof TERadio){
				return new ContainerRadio(speler.inventory,(TERadio)tileentity);
			}
		}*/
		switch(ID){
		case Constante.guiRadio:
			if(tileentity instanceof TERadio){
				return new ContainerRadio(speler.inventory,(TERadio)tileentity,speler);
			}
			break;
		case Constante.guiJukeBox:
			if(tileentity instanceof TEjukeBox){
				return new ContainerRadio(speler.inventory,(TEjukeBox)tileentity,speler);
			}
			break;
		}
		throw new IllegalArgumentException("["+Constante.MODNAME+"] no Correct GUI ID "+ID);
	}
	/**public static void InventariesInit(EntityPlayer speler,World wereld,int x,int y, int z){
		if (ToetsenBinden.inventaries.isPressed())
			System.out.println("toets inventaries werkt");
			FMLNetworkHandler.openGui(speler, R2S_UsefulBlocks.instance,Constante.guiRadio, wereld, x, y, z);
			if(Keyboard.isKeyDown(25))
				System.out.println("lol key25");
			}**/
}

this is a direct copy if my class hope you have enough :P

Always looking for new challenges, and happy to help the people where ever I can

1 minute ago, Korlimann said:

I did it like this:


public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (worldIn.isRemote)
        {
            return true;
        }
        else
        {
            FMLNetworkHandler.openGui(playerIn, Main.instance, Reference.GUI_KITCHENBOARD, worldIn, pos.getX(), pos.getY(), pos.getZ());
            playerIn.addStat(StatList.CRAFTING_TABLE_INTERACTION);
            return true;
        }
    }

I guess, according to what you wrote, I called it from the serverside. :D

yes that is correct :P i do this also

Always looking for new challenges, and happy to help the people where ever I can

  • Author
1 minute ago, sir_titi said:

well if you have a Gui that has a "container" yea you will need that.

wait a sec :P


public class R2S_GuiHandler implements IGuiHandler {
	private GameSettings sets;
	/**test
	public void onKeyInput(InputEvent.KeyInputEvent event, EntityPlayer speler, World wereld,int x, int y, int z) {
		if(ToetsenBinden.pong.isPressed())
			speler.openGui(R2S_UsefulBlocks.instance, 1, wereld, x, y, z);
	}				**/
	public enum GUIIDS{
		guiRadio;
	}
	
	public Object getClientGuiElement(int ID, EntityPlayer speler, World wereld,int x, int y, int z) {
		TileEntity tileentity = wereld.getTileEntity(new BlockPos(x, y, z));
	//	speler.getPersistentID();
		/**if(ToetsenBinden.inventaries.isPressed()){
			System.out.println("test bctGuihandler guiharnas");
		speler.openGui(R2S_UsefulBlocks.instance, Constante.guiHarnas, wereld, x, y, z);}				**/
		/*switch(GUIIDS.values()[ID]){
		case guiRadio:
			if(tileentity instanceof TERadio){
				return new GuiRadio(speler.inventory,(TERadio)tileentity);
			}
		}*/
		switch(ID){
		case Constante.guiRadio:
			if(tileentity instanceof TERadio){
				return new GuiRadio(speler.inventory,speler,(TERadio)tileentity,wereld,x,y,z);
			}
			break;
		case Constante.guiJukeBox:
			if(tileentity instanceof TEjukeBox){
				return new GuiJukeBox(speler.inventory,speler,(TEjukeBox)tileentity,wereld,x,y,z);
			}
			break;
		}
		throw new IllegalArgumentException("["+Constante.MODNAME+"] no Correct GUI ID : "+ID);
	}
	public Object getServerGuiElement(int ID, EntityPlayer speler, World wereld, int x, int y, int z) {
		TileEntity tileentity = wereld.getTileEntity(new BlockPos(x, y, z));
		//speler.getPersistentID();
		/**if (ToetsenBinden.inventaries.isPressed()){
			System.out.println("test bctGuihandler guiharnas");
		speler.openGui(R2S_UsefulBlocks.instance, Constante.guiHarnas, wereld, x, y, z);}							**/
		/*switch(GUIIDS.values()[ID]){
		case guiRadio:
			if(tileentity instanceof TERadio){
				return new ContainerRadio(speler.inventory,(TERadio)tileentity);
			}
		}*/
		switch(ID){
		case Constante.guiRadio:
			if(tileentity instanceof TERadio){
				return new ContainerRadio(speler.inventory,(TERadio)tileentity,speler);
			}
			break;
		case Constante.guiJukeBox:
			if(tileentity instanceof TEjukeBox){
				return new ContainerRadio(speler.inventory,(TEjukeBox)tileentity,speler);
			}
			break;
		}
		throw new IllegalArgumentException("["+Constante.MODNAME+"] no Correct GUI ID "+ID);
	}
	/**public static void InventariesInit(EntityPlayer speler,World wereld,int x,int y, int z){
		if (ToetsenBinden.inventaries.isPressed())
			System.out.println("toets inventaries werkt");
			FMLNetworkHandler.openGui(speler, R2S_UsefulBlocks.instance,Constante.guiRadio, wereld, x, y, z);
			if(Keyboard.isKeyDown(25))
				System.out.println("lol key25");
			}**/
}

this is a direct copy if my class hope you have enough :P

Can I just use this for mine? :D And, will I need to change my "BlockBaseCraftingTable" class too?

yea sure but i'm pretty sure you will have to change allot :P

And normally no you don't have to change anything there.

Always looking for new challenges, and happy to help the people where ever I can

  • Author
Just now, sir_titi said:

yea sure but i'm pretty sure you will have to change allot :P

And normally no you don't have to change anything there.

Thanks, I'll try it out. :D

good luck, but wait a sec :P i give you the needed stuff from scratch.

public class R2S_GuiHandler implements IGuiHandler {
	
	public Object getClientGuiElement(int ID, EntityPlayer speler, World wereld,int x, int y, int z) {
		
	}
	public Object getServerGuiElement(int ID, EntityPlayer speler, World wereld, int x, int y, int z) {
		
	}

these are the important method's 

Always looking for new challenges, and happy to help the people where ever I can

  • Author
1 minute ago, sir_titi said:

good luck, but wait a sec :P i give you the needed stuff from scratch.


public class R2S_GuiHandler implements IGuiHandler {
	
	public Object getClientGuiElement(int ID, EntityPlayer speler, World wereld,int x, int y, int z) {
		
	}
	public Object getServerGuiElement(int ID, EntityPlayer speler, World wereld, int x, int y, int z) {
		
	}

these are the important method's 

So, I won't need anything else than this two methods? :3

haah normally nope :p, but these just handle you GUI's nothing more :P

Always looking for new challenges, and happy to help the people where ever I can

  • Author
Just now, sir_titi said:

haah normally nope :p, but these just handle you GUI's nothing more :P

I meant, I won't need any additional methods than those two, sorry. xD

Do you have a tutorial for me on what actually needs to be in those methods?

well that's alot off work for me mate :P

but to keep it simple (this is for the Client)

switch(ID){//just switch the "GUI" id's and return the proper GUI class and that's it :p
		case Constante.guiRadio:
			if(tileentity instanceof TERadio){
				return new GuiRadio(speler.inventory,speler,(TERadio)tileentity,wereld,x,y,z);
			}
			break;
		case Constante.guiJukeBox:
			if(tileentity instanceof TEjukeBox){
				return new GuiJukeBox(speler.inventory,speler,(TEjukeBox)tileentity,wereld,x,y,z);
			}
			break;
		}
		throw new IllegalArgumentException("["+Constante.MODNAME+"] no Correct GUI ID : "+ID);

and the server

	switch(ID){//the same but here you should return the container
		case Constante.guiRadio:
			if(tileentity instanceof TERadio){
				return new ContainerRadio(speler.inventory,(TERadio)tileentity,speler);
			}
			break;
		case Constante.guiJukeBox:
			if(tileentity instanceof TEjukeBox){
				return new ContainerRadio(speler.inventory,(TEjukeBox)tileentity,speler);
			}
			break;
		}
		throw new IllegalArgumentException("["+Constante.MODNAME+"] no Correct GUI ID "+ID);

 

Edited by sir_titi

Always looking for new challenges, and happy to help the people where ever I can

  • Author
1 minute ago, sir_titi said:

well that's alot off work for me mate :P

but to keep it simple 


switch(ID){//just switch the "GUI" id's and return the proper GUI class and that's it :p
		case Constante.guiRadio:
			if(tileentity instanceof TERadio){
				return new GuiRadio(speler.inventory,speler,(TERadio)tileentity,wereld,x,y,z);
			}
			break;
		case Constante.guiJukeBox:
			if(tileentity instanceof TEjukeBox){
				return new GuiJukeBox(speler.inventory,speler,(TEjukeBox)tileentity,wereld,x,y,z);
			}
			break;
		}
		throw new IllegalArgumentException("["+Constante.MODNAME+"] no Correct GUI ID : "+ID);

 

Thanks, I'll try and implement it. :D

yea no prob mate ;), best off luck to you :D.Let's hope you fix it. (fingers crossed)

Always looking for new challenges, and happy to help the people where ever I can

  • Author
1 minute ago, sir_titi said:

yea no prob mate ;), best off luck to you :D.Let's hope you fix it. (fingers crossed)

So, I guess I have to change the GUI ID, corresponding to the id of the gui I want to show. But what do I have to do with the containers?

  • Author

Originally, I just wanted to show the normal workbench gui, I don't think I even want to show a custom gui. Will I still need to implement all of this? xD

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.