Jump to content

Recommended Posts

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

Posted

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

  • Like 1

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

Posted
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

Posted (edited)
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
Posted
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

 

Posted

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

}

 

  • Like 1

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

Posted
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

Posted

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

  • Like 1

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

Posted
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

  • Like 1

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

Posted
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?

Posted

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.

  • Like 1

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

Posted

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 

  • Like 1

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

Posted
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

Posted
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?

Posted (edited)

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
  • Like 1

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

Posted
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

Posted
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?

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



×
×
  • Create New...

Important Information

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