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