Posted February 14, 20187 yr 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. Cheers and have a nice evening Korlimann
February 14, 20187 yr 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 Greets Sir_titi Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr 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
February 14, 20187 yr no in your case in your onBlockActivated(args) Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr 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 February 14, 20187 yr by Korlimann
February 14, 20187 yr did you call this on server side cuss this should work Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr did you make a class that implements "IGuiHandler" Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr Author 1 minute ago, sir_titi said: did you call this on server side cuss this should work ...what do you mean by "on the server side"? 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?
February 14, 20187 yr haha LOL well pretty easy 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
February 14, 20187 yr Author Just now, sir_titi said: did you make a class that implements "IGuiHandler" Nope. I guess I'll need this?
February 14, 20187 yr Author Just now, sir_titi said: haha LOL well pretty easy 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.
February 14, 20187 yr well if you have a Gui that has a "container" yea you will need that. wait a sec 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 Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr 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. yes that is correct i do this also Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr 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 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 Can I just use this for mine? And, will I need to change my "BlockBaseCraftingTable" class too?
February 14, 20187 yr yea sure but i'm pretty sure you will have to change allot 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
February 14, 20187 yr Author Just now, sir_titi said: yea sure but i'm pretty sure you will have to change allot And normally no you don't have to change anything there. Thanks, I'll try it out.
February 14, 20187 yr good luck, but wait a sec 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
February 14, 20187 yr Author 1 minute ago, sir_titi said: good luck, but wait a sec 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
February 14, 20187 yr haah normally nope :p, but these just handle you GUI's nothing more Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr Author Just now, sir_titi said: haah normally nope :p, but these just handle you GUI's nothing more I meant, I won't need any additional methods than those two, sorry. Do you have a tutorial for me on what actually needs to be in those methods?
February 14, 20187 yr well that's alot off work for me mate 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 February 14, 20187 yr by sir_titi Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr Author 1 minute ago, sir_titi said: well that's alot off work for me mate 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.
February 14, 20187 yr yea no prob mate , best off luck to you .Let's hope you fix it. (fingers crossed) Always looking for new challenges, and happy to help the people where ever I can
February 14, 20187 yr Author 1 minute ago, sir_titi said: yea no prob mate , best off luck to you .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?
February 14, 20187 yr 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?
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.