Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8] ItemStacks disappearing when moved in GUI, qty wrong o_0


RoseCotton
 Share

Recommended Posts

Hi, All.

I was trying to add code to render items on my shelf block when they're contained in the shelf's tile entity and I broke its container properties.

Now, in the GUI, if I left-click on an item placed in the shelf, it disappears.

If I right-click on an item in the shelf, it cuts the quantity in half, deletes half, and leaves 1/4 in the shelf and I can place 1/4 in my regular inventory.  if I take that stack from inventory and put it back on the item in the shelf I got it from, I get 3/4 what I started with (so, like the item stack in inventory actually had 2x the quantity it was reporting).

 

I'll say what I say each time I screw up my code... "I didn't change anything that should do this!"

I've been combing through the code and can't find how I can even screw this up so bad.  Can you find the blatant error?

 

console data gives no clues.

 

 

[04:18:58] [main/INFO] [GradleStart]: Extra: []

[04:18:58] [main/INFO] [GradleStart]: Running with arguments: [--userProperties, {}, --assetsDir, C:/Users/Becky/.gradle/caches/minecraft/assets, --assetIndex, 1.8, --accessToken, {REDACTED}, --version, 1.8, --tweakClass, net.minecraftforge.fml.common.launcher.FMLTweaker, --tweakClass, net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker]

[04:18:58] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker

[04:18:58] [main/INFO] [LaunchWrapper]: Using primary tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker

[04:18:58] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker

[04:18:58] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLTweaker

[04:18:58] [main/INFO] [FML]: Forge Mod Loader version 8.0.20.1023 for Minecraft 1.8 loading

[04:18:58] [main/INFO] [FML]: Java is Java HotSpot Client VM, version 1.8.0_31, running on Windows 7:x86:6.1, installed at C:\Program Files\Java\jre1.8.0_31

[04:18:58] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation

[04:18:58] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker

[04:18:58] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.fml.relauncher.FMLCorePlugin

[04:18:58] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker

[04:18:58] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLDeobfTweaker

[04:18:58] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker

[04:18:58] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker

[04:18:58] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper

[04:18:58] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!

[04:19:00] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing

[04:19:00] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLDeobfTweaker

[04:19:00] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.TerminalTweaker

[04:19:00] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.TerminalTweaker

[04:19:00] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}

[04:19:01] [Client thread/INFO]: Setting user: Player688

[04:19:01] [Client thread/INFO]: (Session ID is token:FML:Player688)

[04:19:04] [Client thread/INFO]: LWJGL Version: 2.9.1

[04:19:05] [Client thread/INFO] [MinecraftForge]: Attempting early MinecraftForge initialization

[04:19:05] [Client thread/INFO] [MinecraftForge]: Completed early MinecraftForge initialization

[04:19:05] [Client thread/INFO] [FML]: Searching C:\Users\Becky\Desktop\Forge ModLoader-1.8-8.0.20.1023-1.8-src\eclipse\mods for mods

[04:19:08] [Client thread/INFO] [FML]: Forge Mod Loader has identified 5 mods to load

[04:19:08] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, testmod01, oredetectmod, shelvesmod] at CLIENT

[04:19:08] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, testmod01, oredetectmod, shelvesmod] at SERVER

[04:19:09] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Test Mod 01, FMLFileResourcePack:Ore Detect Mod, FMLFileResourcePack:Shelves Mod

[04:19:09] [Client thread/INFO] [FML]: Processing ObjectHolder annotations

[04:19:09] [Client thread/INFO] [FML]: Found 384 ObjectHolder annotations

[04:19:09] [Client thread/INFO] [sTDOUT]: [com.rosecotton.shelvesmod.GuiHandlerShelf:getGuiID:19]: Called method: GuiHandlerShelf.getGuiID

[04:19:09] [Client thread/INFO] [FML]: Applying holder lookups

[04:19:09] [Client thread/INFO] [FML]: Holder lookups applied

[04:19:09] [sound Library Loader/INFO]: Starting up SoundSystem...

[04:19:09] [Thread-7/INFO]: Initializing LWJGL OpenAL

[04:19:09] [Thread-7/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

[04:19:10] [Thread-7/INFO]: OpenAL initialized.

[04:19:10] [sound Library Loader/INFO]: Sound engine started

[04:19:12] [Client thread/INFO]: Created: 512x512 textures-atlas

[04:19:13] [Client thread/INFO] [sTDOUT]: [com.becky.testmod01.Testmod01:postInit:142]: Called method: postInit

[04:19:13] [Client thread/INFO] [sTDOUT]: [com.rosecotton.oredetect.OreDetectMod:postInit:120]: Called method: postInit

[04:19:13] [Client thread/INFO] [sTDOUT]: [com.rosecotton.shelvesmod.ShelvesMod:postInit:102]: Called method: postInit

[04:19:13] [Client thread/INFO] [FML]: Forge Mod Loader has successfully loaded 5 mods

[04:19:13] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Test Mod 01, FMLFileResourcePack:Ore Detect Mod, FMLFileResourcePack:Shelves Mod

[04:19:13] [Client thread/INFO]: SoundSystem shutting down...

[04:19:14] [Client thread/WARN]: Author: Paul Lamb, www.paulscode.com

[04:19:14] [sound Library Loader/INFO]: Starting up SoundSystem...

[04:19:14] [Thread-9/INFO]: Initializing LWJGL OpenAL

[04:19:14] [Thread-9/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

[04:19:14] [Thread-9/INFO]: OpenAL initialized.

[04:19:14] [sound Library Loader/INFO]: Sound engine started

[04:19:16] [Client thread/INFO]: Created: 512x512 textures-atlas

[04:19:26] [server thread/INFO]: Starting integrated minecraft server version 1.8

[04:19:26] [server thread/INFO]: Generating keypair

[04:19:26] [server thread/INFO] [FML]: Injecting existing block and item data into this server instance

[04:19:26] [server thread/INFO] [FML]: Applying holder lookups

[04:19:26] [server thread/INFO] [FML]: Holder lookups applied

[04:19:27] [server thread/INFO]: Preparing start region for level 0

[04:19:28] [server thread/INFO]: Preparing spawn area: 52%

[04:19:28] [server thread/INFO]: Changing view distance to 8, from 10

[04:19:29] [Netty Local Client IO #0/INFO] [FML]: Server protocol version 1

[04:19:29] [Netty Server IO #1/INFO] [FML]: Client protocol version 1

[04:19:29] [Netty Server IO #1/INFO] [FML]: Client attempting to join with 5 mods : oredetectmod@1.0,FML@8.0.20.1023,shelvesmod@1.0,testmod01@1.0,mcp@9.05

[04:19:29] [Netty Local Client IO #0/INFO] [FML]: [Netty Local Client IO #0] Client side modded connection established

[04:19:29] [server thread/INFO] [FML]: [server thread] Server side modded connection established

[04:19:29] [server thread/INFO]: Player688[local:E:c7e0955e] logged in with entity id 39 at (229.69999998807907, 66.0, -203.30925797377813)

[04:19:29] [server thread/INFO]: Player688 joined the game

[04:19:37] [server thread/INFO] [sTDOUT]: [com.rosecotton.shelvesmod.GuiHandlerShelf:getGuiID:19]: Called method: GuiHandlerShelf.getGuiID

[04:19:37] [server thread/INFO] [sTDOUT]: [com.rosecotton.shelvesmod.GuiHandlerShelf:getGuiID:19]: Called method: GuiHandlerShelf.getGuiID

[04:19:37] [server thread/INFO] [sTDOUT]: [com.rosecotton.shelvesmod.GuiHandlerShelf:getServerGuiElement:33]: Called method: GuiHandlerShelf.getServerGuiElement return good stuff

[04:19:37] [server thread/INFO] [sTDOUT]: [com.rosecotton.shelvesmod.BlockShelf:onBlockActivated:283]: Called method: BlockShelf.onBlockActivated

[04:19:37] [Client thread/INFO] [sTDOUT]: [com.rosecotton.shelvesmod.GuiHandlerShelf:getGuiID:19]: Called method: GuiHandlerShelf.getGuiID

[04:19:37] [Client thread/INFO] [sTDOUT]: [com.rosecotton.shelvesmod.GuiHandlerShelf:getClientGuiElement:51]: Called method: GuiHandlerShelf.getClientGuiElement return good stuff

[04:20:00] [server thread/INFO]: Saving and pausing game...

[04:20:00] [server thread/INFO]: Saving chunks for level 'Survival'/Overworld

[04:20:01] [server thread/INFO]: Saving chunks for level 'Survival'/Nether

[04:20:01] [server thread/INFO]: Saving chunks for level 'Survival'/The End

[04:20:02] [server thread/INFO]: Stopping server

[04:20:02] [server thread/INFO]: Saving players

[04:20:02] [server thread/INFO]: Saving worlds

[04:20:02] [server thread/INFO]: Saving chunks for level 'Survival'/Overworld

[04:20:02] [server thread/INFO]: Saving chunks for level 'Survival'/Nether

[04:20:02] [server thread/INFO]: Saving chunks for level 'Survival'/The End

[04:20:02] [server thread/INFO] [FML]: Applying holder lookups

[04:20:02] [server thread/INFO] [FML]: Holder lookups applied

[04:20:02] [Client thread/INFO]: Stopping!

[04:20:02] [Client thread/INFO]: SoundSystem shutting down...

[04:20:02] [Client thread/WARN]: Author: Paul Lamb, www.paulscode.com

Java HotSpot Client VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

 

 

 

package com.rosecotton.shelvesmod;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.LanguageRegistry;
import net.minecraftforge.fml.relauncher.Side;

import com.rosecotton.shelvesmod.BlockShelf;
//import com.becky.testmod01.Testmod01;

@Mod(modid = ShelvesMod.MODID, name = ShelvesMod.MODNAME, version = ShelvesMod.VERSION) 

public class ShelvesMod 
{

  public static Block shelfBlock;
  //public static Item brickIngot;
  public static final String MODID = "shelvesmod";
  public static final String MODNAME = "RoseCotton's Shelves Mod for 1.8";
  public static final String VERSION = "1.0";
  public static int type;

  @Instance(value = "shelvesmod")
  public static ShelvesMod instance = new ShelvesMod();
  
  public static class MySidedProxyHolder {
	  @SidedProxy(modId="shelvesmod",clientSide="com.rosecotton.shelvesmod.ClientProxy", serverSide="com.rosecotton.shelvesmod.CommonProxy")
	  public static CommonProxy proxy;
	  }
	  
	  public class CommonProxy {
		  // Common or server stuff here that needs to be overridden on the client
	  }
	  public class ClientProxy extends CommonProxy {
		  // Override common stuff with client specific stuff here
	  }

  @EventHandler
  public void preInit(FMLPreInitializationEvent event) 
  {

  	//blocks
  	shelfBlock = new BlockShelf(type);
  	LanguageRegistry.addName(shelfBlock, "Shelf Block");
  	
  	GameRegistry.registerTileEntity(ShelfTitleEntity.class, "shelfTitleEntity");
  	//was com.rosecotton.shelvesmod.ShelfTitleEntity.class
  	
  	
  	//items
  	//brickIngot = new ItemBrickIngot();
	  //MOVE GAMEREGISTRY TO ITEM CLASS?
  	//GameRegistry.registerItem(brickIngot, ((ItemBrickIngot) brickIngot).getName());
  	//LanguageRegistry.addName(brickIngot, "Brick Ingot");
	NetworkRegistry.INSTANCE.registerGuiHandler(ShelvesMod.instance, GuiHandlerRegistry.getInstance());
	GuiHandlerRegistry.getInstance().registerGuiHandler(new GuiHandlerShelf(), GuiHandlerShelf.getGuiID());
  }

  @EventHandler
  public void init(FMLInitializationEvent event) 
  {
  	//System.out.println("Called method: init");
  
  	if(event.getSide() == Side.CLIENT)
  	{
  		
  		RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();

  		renderItem.getItemModelMesher().register(Item.getItemFromBlock(shelfBlock), 0, new ModelResourceLocation(ShelvesMod.MODID + ":" + ((BlockShelf) shelfBlock).getName(), "shelfBlock"));
  		Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(shelfBlock),0, new ModelResourceLocation(ShelvesMod.MODID+":"+ "shelfBlock", "inventory"));
  		
//	  	    ClientRegistry.bindTileEntitySpecialRenderer(ShelfTitleEntity.class, new TileEntitySpecialRendererShelf());
  	}
  	
  	//recipes
  	GameRegistry.addRecipe(new ItemStack(shelfBlock), new Object[]{
  	"   ",
  	"  A",
  	" AA",
  	'A', Items.stick //getItemFromBlock(Blocks.planks)
  	});
  }
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) 
    {
    	System.out.println("Called method: postInit");
    }
}

 

package com.rosecotton.shelvesmod;

//import BlockStairs;

import java.util.Iterator;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.ILockableContainer;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;


public class BlockShelf extends BlockContainer {

    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
    public static final PropertyEnum SECTION = PropertyEnum.create("section", BlockShelf.EnumShape.class);
    
    private final Random rand = new Random();
   // private static final String __OBFID = "CL_00000214";
private final String name = "shelfBlock";
ModelResourceLocation modelresourcelocation = new ModelResourceLocation("shelvesmod"+":"+name, "inventory");
    
    protected BlockShelf(int type)
    {
        super(Material.wood);
        //TEH FOLLOWIONG LINE MIGHT HAVE BEEN USEFUL BUT MAYBE CAUSED AN ERROR AT RUNTIME, TRY AGAIN
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
        //this.chestType = type;
        this.setCreativeTab(CreativeTabs.tabMisc);
        this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
        this.useNeighborBrightness = true;
	this.setDefaultState(this.blockState.getBaseState());
        GameRegistry.registerBlock(this, name);
    	this.setUnlocalizedName(ShelvesMod.MODID + "_" + name);
    	this.setBlockBounds(1/16.0F, 0, 1/16.0F, 15/16.0F, 8/16.0F, 15/16.0F);
    }

    public String toString()
    {
        return this.name;
    }
    public String getName()
    {
        return this.name;
    }

    // used by the renderer to control lighting and visibility of other blocks.
    // set to false because this block doesn't fill the entire 1x1x1 space
    @Override
    public boolean isOpaqueCube() {
      return false;
    }

    // used by the renderer to control lighting and visibility of other blocks, also by
    // (eg) wall or fence to control whether the fence joins itself to this block
    // set to false because this block doesn't fill the entire 1x1x1 space
    @Override
    public boolean isFullCube() {
      return false;
    }
    
    // this function returns the correct item type corresponding to the colour of our block;
    // i.e. when a sign is broken, it will drop the correct item.
    @Override
    public int damageDropped(IBlockState state)
    {
      //EnumColour enumColour = (EnumColour)state.getValue(PROPERTYCOLOUR);
      //return this.getMetadata();//enumColour.getMetadata();
    	return 0;
    }
    

    
    
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
    {
        if (worldIn.getBlockState(pos.north()).getBlock() == this)
        {
            this.setBlockBounds(0.0625F, 0.0F, 0.0F, 0.9375F, 0.875F, 0.9375F);
        }
        else if (worldIn.getBlockState(pos.south()).getBlock() == this)
        {
            this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 1.0F);
        }
        else if (worldIn.getBlockState(pos.west()).getBlock() == this)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
        }
        else if (worldIn.getBlockState(pos.east()).getBlock() == this)
        {
            this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F, 0.875F, 0.9375F);
        }
        else
        {
            this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
        }
    }

    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {
        //this.checkForSurroundingChests(worldIn, pos, state);
        Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();

        while (iterator.hasNext())
        {
            EnumFacing enumfacing = (EnumFacing)iterator.next();
            BlockPos blockpos1 = pos.offset(enumfacing);
            IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);

        }
    }
@Override
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase player)
    {
        return this.getDefaultState().withProperty(FACING, player.getHorizontalFacing());
    }

    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
    {
        EnumFacing enumfacing = EnumFacing.getHorizontal(MathHelper.floor_double((double)(placer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3).getOpposite();
        state = state.withProperty(FACING, enumfacing);
        BlockPos blockpos1 = pos.north();
        BlockPos blockpos2 = pos.south();
        BlockPos blockpos3 = pos.west();
        BlockPos blockpos4 = pos.east();
        boolean flag = this == worldIn.getBlockState(blockpos1).getBlock();
        boolean flag1 = this == worldIn.getBlockState(blockpos2).getBlock();
        boolean flag2 = this == worldIn.getBlockState(blockpos3).getBlock();
        boolean flag3 = this == worldIn.getBlockState(blockpos4).getBlock();

        if (!flag && !flag1 && !flag2 && !flag3)
        {
            worldIn.setBlockState(pos, state, 3);
        }
        else if (enumfacing.getAxis() == EnumFacing.Axis.X && (flag || flag1))
        {
            if (flag)
            {
                worldIn.setBlockState(blockpos1, state, 3);
            }
            else
            {
                worldIn.setBlockState(blockpos2, state, 3);
            }

            worldIn.setBlockState(pos, state, 3);
        }
        else if (enumfacing.getAxis() == EnumFacing.Axis.Z && (flag2 || flag3))
        {
            if (flag2)
            {
                worldIn.setBlockState(blockpos3, state, 3);
            }
            else
            {
                worldIn.setBlockState(blockpos4, state, 3);
            }

            worldIn.setBlockState(pos, state, 3);
        }

        if (stack.hasDisplayName())
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityChest)
            {
                ((TileEntityChest)tileentity).setCustomName(stack.getDisplayName());
            }
        }
    }
    
    public IBlockState correctFacing(World worldIn, BlockPos pos, IBlockState state)
    {
        EnumFacing enumfacing = null;
        Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();

        while (iterator.hasNext())
        {
            EnumFacing enumfacing1 = (EnumFacing)iterator.next();
            IBlockState iblockstate1 = worldIn.getBlockState(pos.offset(enumfacing1));

            if (iblockstate1.getBlock() == this)
            {
                return state;
            }

            if (iblockstate1.getBlock().isFullBlock())
            {
                if (enumfacing != null)
                {
                    enumfacing = null;
                    break;
                }

                enumfacing = enumfacing1;
            }
        }

        if (enumfacing != null)
        {
            return state.withProperty(FACING, enumfacing.getOpposite());
        }
        else
        {
            EnumFacing enumfacing2 = (EnumFacing)state.getValue(FACING);

            if (worldIn.getBlockState(pos.offset(enumfacing2)).getBlock().isFullBlock())
            {
                enumfacing2 = enumfacing2.getOpposite();
            }

            if (worldIn.getBlockState(pos.offset(enumfacing2)).getBlock().isFullBlock())
            {
                enumfacing2 = enumfacing2.rotateY();
            }

            if (worldIn.getBlockState(pos.offset(enumfacing2)).getBlock().isFullBlock())
            {
                enumfacing2 = enumfacing2.getOpposite();
            }

            return state.withProperty(FACING, enumfacing2);
        }
    }





    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof IInventory)
        {
            InventoryHelper.dropInventoryItems(worldIn, pos, (IInventory)tileentity);
            worldIn.updateComparatorOutputLevel(pos, this);
        }

        super.breakBlock(worldIn, pos, state);
    }
    

// Called when the block is right clicked
// In this block it is used to open the blocks gui when right clicked by a player
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
	// Uses the gui handler registered to your mod to open the gui for the given gui id
	// open on the server side only  (not sure why you shouldn't open client side too... vanilla doesn't, so we better not either)
	if (worldIn.isRemote) return true;

	playerIn.openGui(ShelvesMod.instance, GuiHandlerShelf.getGuiID(), worldIn, pos.getX(), pos.getY(), pos.getZ());
   	System.out.println("Called method: BlockShelf.onBlockActivated");
	return true;
}

@Override
   public TileEntity createNewTileEntity(World worldIn, int meta)
    {
        return new ShelfTitleEntity();
    }



    private boolean isBlocked(World worldIn, BlockPos pos)
    {
        return this.isBelowSolidBlock(worldIn, pos) || this.isOcelotSittingOnChest(worldIn, pos);
    }

    private boolean isBelowSolidBlock(World worldIn, BlockPos pos)
    {
        return worldIn.getBlockState(pos.up()).getBlock().isNormalCube();
    }




    private boolean isOcelotSittingOnChest(World worldIn, BlockPos pos)
    {
        Iterator iterator = worldIn.getEntitiesWithinAABB(EntityOcelot.class, new AxisAlignedBB((double)pos.getX(), (double)(pos.getY() + 1), (double)pos.getZ(), (double)(pos.getX() + 1), (double)(pos.getY() + 2), (double)(pos.getZ() + 1))).iterator();
        EntityOcelot entityocelot;

        do
        {
            if (!iterator.hasNext())
            {
                return false;
            }

            Entity entity = (Entity)iterator.next();
            entityocelot = (EntityOcelot)entity;
        }
        while (!entityocelot.isSitting());

        return true;
    }

    public boolean hasComparatorInputOverride()
    {
        return true;
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        EnumFacing enumfacing = EnumFacing.getFront(meta);

        if (enumfacing.getAxis() == EnumFacing.Axis.Y)
        {
            enumfacing = EnumFacing.NORTH;
        }

        return this.getDefaultState().withProperty(FACING, enumfacing);
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
      EnumFacing facing = (EnumFacing)state.getValue(FACING);

      int facingbits = facing.getHorizontalIndex();
      return facingbits;// | colourbits;
    }

    // necessary to define which properties your blocks use
    // will also affect the variants listed in the blockstates model file
    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, new IProperty[] {FACING,SECTION});
    }

    
    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return Item.getItemFromBlock(this);
    }
    public static enum EnumShape implements IStringSerializable
    {
        TOP("top"),
        MIDDLE("middle"),
        BOTTOM("bottom");

        private final String name;

        private static final String __OBFID = "CL_00003061";

        private EnumShape(String name)
        {
            this.name = name;
        }

        public String toString()
        {
            return this.name;
        }

        public String getName()
        {
            return this.name;
        }

    }
    public TileEntity createTileEntity(World world, int metadata)
    {
       return new ShelfTitleEntity();
    }
    
    @Override
    public int getRenderType()
    {
        return 3;
    }
    
}

 

package com.rosecotton.shelvesmod;

import com.rosecotton.shelvesmod.ShelvesMod;

public class ShelvesEventHandler {
}

 

package com.rosecotton.shelvesmod;
import java.util.Arrays;

import net.minecraft.block.BlockChest;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import net.minecraft.nbt.NBTTagList;

public class ShelfTitleEntity extends TileEntity implements IInventory {
final static int NUMBER_OF_SLOTS = 4;
    public int numPlayersUsing;
public static ItemStack[] itemStacks = new ItemStack[NUMBER_OF_SLOTS];
//public EntityItem itemEnt[] = null;



// will add a key for this container to the lang file so we can name it in the GUI
@Override
public String getName() {
	return "Block Shelf";
}

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

// standard code to look up what the human-readable name is
@Override
public IChatComponent getDisplayName() {
	return this.hasCustomName() ? new ChatComponentText(this.getName()) : new ChatComponentTranslation(this.getName());
}

@Override
public int getSizeInventory() {
	return itemStacks.length;
}


@Override
public ItemStack getStackInSlot(int slotIndex) {
	return itemStacks[slotIndex];
	}

@Override
public ItemStack decrStackSize(int slotIndex, int count) {
	ItemStack itemStackInSlot = getStackInSlot(slotIndex);
	if (itemStackInSlot == null) return null;

	ItemStack itemStackRemoved;
	if (itemStackInSlot.stackSize <= count) {
		itemStackRemoved = itemStackInSlot;
		setInventorySlotContents(slotIndex, null);
	} else {
		itemStackRemoved = itemStackInSlot.splitStack(count);
		if (itemStackInSlot.stackSize == 0) {
			setInventorySlotContents(slotIndex, null);
		}
	}
	markDirty();
  	return itemStackRemoved;
}

// -----------------------------------------------------------------------------------------------------------
// The following method is not needed for this example but are part of IInventory so must be implemented
/**
 * This method removes the entire contents of the given slot and returns it.
 * Used by containers such as crafting tables which return any items in their slots when you close the GUI
 * @param slotIndex
 * @return
 */
@Override
public ItemStack getStackInSlotOnClosing(int slotIndex) {
	ItemStack itemStack = getStackInSlot(slotIndex);
	if (itemStack != null) setInventorySlotContents(slotIndex, null);
	return itemStack;
}

// overwrites the stack in the given slotIndex with the given stack
@Override
public void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
	itemStacks[slotIndex] = itemstack;
	if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
		itemstack.stackSize = getInventoryStackLimit();
	}
	//RenderShelfTileEntity renderShelfTileEntity = new RenderShelfTileEntity(this);
	markDirty();
}

// This is the maximum number if items allowed in each slot
// This only affects things such as hoppers trying to insert items you need to use the container to enforce this for players
// inserting items via the gui
@Override
public int getInventoryStackLimit() {
	return 64;
}

// Return true if the given player is able to use this block. In this case it checks that
// 1) the world tileentity hasn't been replaced in the meantime, and
// 2) the player isn't too far away from the centre of the block
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	if (this.worldObj.getTileEntity(this.pos) != this) return false;
	final double X_CENTRE_OFFSET = 0.5;
	final double Y_CENTRE_OFFSET = 0.5;
	final double Z_CENTRE_OFFSET = 0.5;
	final double MAXIMUM_DISTANCE_SQ = 8.0 * 8.0;
	return player.getDistanceSq(pos.getX() + X_CENTRE_OFFSET, pos.getY() + Y_CENTRE_OFFSET, pos.getZ() + Z_CENTRE_OFFSET) < MAXIMUM_DISTANCE_SQ;
}

//-----------------------------------------------------------------------------------------------------------
//The following method is not needed for this example but are part of IInventory so must be implemented
@Override
public void openInventory(EntityPlayer player) {
    if (!player.isSpectator())
    {
        if (this.numPlayersUsing < 0)
        {
            this.numPlayersUsing = 0;
        }

        ++this.numPlayersUsing;
        this.worldObj.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing);
        this.worldObj.notifyNeighborsOfStateChange(this.pos, this.getBlockType());
        this.worldObj.notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType());
    	System.out.println("Called method: ShelfTitleEntity.openInventory");
    }
}

//-----------------------------------------------------------------------------------------------------------
//The following method is not needed for this example but are part of IInventory so must be implemented
@Override
public void closeInventory(EntityPlayer player) {
    if (!player.isSpectator() && this.getBlockType() instanceof BlockChest)
    {
        --this.numPlayersUsing;
        this.worldObj.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing);
        this.worldObj.notifyNeighborsOfStateChange(this.pos, this.getBlockType());
        this.worldObj.notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType());
    }
}

// Return true if the given stack is allowed to go in the given slot.  In this case, we can insert anything.
// This only affects things such as hoppers trying to insert items you need to use the container to enforce this for players
// inserting items via the gui
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
	return true;
}


// This is where you save any data that you don't want to lose when the tile entity unloads
// In this case, it saves the itemstacks stored in the container
@Override
public void writeToNBT(NBTTagCompound parentNBTTagCompound)
{
	super.writeToNBT(parentNBTTagCompound); // The super call is required to save and load the tileEntity's location

	// to use an analogy with Java, this code generates an array of hashmaps
	// The itemStack in each slot is converted to an NBTTagCompound, which is effectively a hashmap of key->value pairs such
	//   as slot=1, id=2353, count=1, etc
	// Each of these NBTTagCompound are then inserted into NBTTagList, which is similar to an array.
	NBTTagList dataForAllSlots = new NBTTagList();
	for (int i = 0; i < this.itemStacks.length; ++i) {
		if (this.itemStacks[i] != null)	{
			NBTTagCompound dataForThisSlot = new NBTTagCompound();
			dataForThisSlot.setByte("Slot", (byte) i);
			this.itemStacks[i].writeToNBT(dataForThisSlot);
			dataForAllSlots.appendTag(dataForThisSlot);
		}
	}
	// the array of hashmaps is then inserted into the parent hashmap for the container
	parentNBTTagCompound.setTag("Items", dataForAllSlots);
}

// This is where you load the data that you saved in writeToNBT
@Override
public void readFromNBT(NBTTagCompound parentNBTTagCompound)
{
	super.readFromNBT(parentNBTTagCompound); // The super call is required to save and load the tiles location

	final byte NBT_TYPE_COMPOUND = 10;       // See NBTBase.createNewByType() for a listing
	NBTTagList dataForAllSlots = parentNBTTagCompound.getTagList("Items", NBT_TYPE_COMPOUND);

	Arrays.fill(itemStacks, null);           // set all slots to empty
	for (int i = 0; i < dataForAllSlots.tagCount(); ++i) {
		NBTTagCompound dataForOneSlot = dataForAllSlots.getCompoundTagAt(i);
		int slotIndex = dataForOneSlot.getByte("Slot") & 255;

		if (slotIndex >= 0 && slotIndex < this.itemStacks.length) {
			this.itemStacks[slotIndex] = ItemStack.loadItemStackFromNBT(dataForOneSlot);
		}
	}
}

public boolean receiveClientEvent(int id, int type)
{
    if (id == 1)
    {
        this.numPlayersUsing = type;
        return true;
    }
    else
    {
        return super.receiveClientEvent(id, type);
    }
}

@Override
public int getField(int id) {
	return Item.getIdFromItem(itemStacks[id].getItem());
}

@Override
public void setField(int id, int value) {
	itemStacks[id].setItem(Item.getItemById(value));
}

@Override
public int getFieldCount() {
	return itemStacks.length;
}

// set all slots to empty
@Override
public void clear() {
	Arrays.fill(itemStacks, null);
}
}

 

package com.rosecotton.shelvesmod;



import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

/**
* User: brandon3055
* Date: 06/01/2015
*
* The container is used to link the client side gui to the server side inventory and it is where
* you add the slots to your gui. It can also be used to sync server side data with the client but
* that will be covered in a later tutorial
*/
public class ContainerShelf extends Container {

// Stores a reference to the tile entity instance for later use
private ShelfTitleEntity ShelfTitleEntity;

// must assign a slot number to each of the slots used by the GUI.
// For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar.
// Each time we add a Slot to the container, it automatically increases the slotIndex, which means
//  0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 
//  9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
//  36 - 39 = TileInventory slots, which map to our TileEntity slot numbers 0 - 3)

private final int HOTBAR_SLOT_COUNT = 9;
private final int PLAYER_INVENTORY_ROW_COUNT = 3;
private final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
private final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
private final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;

private final int VANILLA_FIRST_SLOT_INDEX = 0;
private final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
private final int TE_INVENTORY_SLOT_COUNT = 4;

public ContainerShelf(InventoryPlayer invPlayer, ShelfTitleEntity ShelfTitleEntity) {
	this.ShelfTitleEntity = ShelfTitleEntity;

	final int SLOT_X_SPACING = 18;
	final int SLOT_Y_SPACING = 18;
	final int HOTBAR_XPOS = 8;
	final int HOTBAR_YPOS = 109;
	// Add the players hotbar to the gui - the [xpos, ypos] location of each item
	for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) {
		int slotNumber = x;
		addSlotToContainer(new Slot(invPlayer, slotNumber, HOTBAR_XPOS + SLOT_X_SPACING * x, HOTBAR_YPOS));
	}

	final int PLAYER_INVENTORY_XPOS = 8;
	final int PLAYER_INVENTORY_YPOS = 51;
	// Add the rest of the players inventory to the gui
	for (int y = 0; y < PLAYER_INVENTORY_ROW_COUNT; y++) {
		for (int x = 0; x < PLAYER_INVENTORY_COLUMN_COUNT; x++) {
			int slotNumber = HOTBAR_SLOT_COUNT + y * PLAYER_INVENTORY_COLUMN_COUNT + x;
			int xpos = PLAYER_INVENTORY_XPOS + x * SLOT_X_SPACING;
			int ypos = PLAYER_INVENTORY_YPOS + y * SLOT_Y_SPACING;
			addSlotToContainer(new Slot(invPlayer, slotNumber,  xpos, ypos));
		}
	}

	if (TE_INVENTORY_SLOT_COUNT != ShelfTitleEntity.getSizeInventory()) {
		System.err.println("Mismatched slot count in ContainerShelf(" + TE_INVENTORY_SLOT_COUNT
											  + ") and TileInventory (" + ShelfTitleEntity.getSizeInventory()+")");
	}
	final int TILE_INVENTORY_XPOS = 8;
	final int TILE_INVENTORY_YPOS = 20;
	// Add the tile inventory container to the gui
	for (int x = 0; x < TE_INVENTORY_SLOT_COUNT; x++) {
		int slotNumber = x;
		addSlotToContainer(new Slot(ShelfTitleEntity, slotNumber, TILE_INVENTORY_XPOS + SLOT_X_SPACING * x, TILE_INVENTORY_YPOS));
	}
}

// Vanilla calls this method every tick to make sure the player is still able to access the inventory, and if not closes the gui
@Override
public boolean canInteractWith(EntityPlayer player)
{
	return ShelfTitleEntity.isUseableByPlayer(player);
}

// This is where you specify what happens when a player shift clicks a slot in the gui
//  (when you shift click a slot in the TileEntity Inventory, it moves it to the first available position in the hotbar and/or
//    player inventory.  When you you shift-click a hotbar or player inventory item, it moves it to the first available
//    position in the TileEntity inventory)
// At the very least you must override this and return null or the game will crash when the player shift clicks a slot
// returns null if the source slot is empty, or if none of the the source slot items could be moved
//   otherwise, returns a copy of the source stack
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int sourceSlotIndex)
{
	Slot sourceSlot = (Slot)inventorySlots.get(sourceSlotIndex);
	if (sourceSlot == null || !sourceSlot.getHasStack()) return null;
	ItemStack sourceStack = sourceSlot.getStack();
	ItemStack copyOfSourceStack = sourceStack.copy();

	// Check if the slot clicked is one of the vanilla container slots
	if (sourceSlotIndex >= VANILLA_FIRST_SLOT_INDEX && sourceSlotIndex < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
		// This is a vanilla container slot so merge the stack into the tile inventory
		if (!mergeItemStack(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT, false)){
			return null;
		}
	} else if (sourceSlotIndex >= TE_INVENTORY_FIRST_SLOT_INDEX && sourceSlotIndex < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) {
		// This is a TE slot so merge the stack into the players inventory
		if (!mergeItemStack(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
			return null;
		}
	} else {
		System.err.print("Invalid slotIndex:" + sourceSlotIndex);
		return null;
	}

	// If stack size == 0 (the entire stack was moved) set slot contents to null
	if (sourceStack.stackSize == 0) {
		sourceSlot.putStack(null);
	} else {
		sourceSlot.onSlotChanged();
	}

	sourceSlot.onPickupFromSlot(player, sourceStack);
	return copyOfSourceStack;
}

// pass the close container message to the tileEntityInventory (not strictly needed for this example)
//  see ContainerChest and TileEntityChest
@Override
public void onContainerClosed(EntityPlayer playerIn)
{
	super.onContainerClosed(playerIn);
	this.ShelfTitleEntity.closeInventory(playerIn);
}
}

 

package com.rosecotton.shelvesmod;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

import java.util.HashMap;

/**
* User: brandon3055
* Date: 06/01/2015
*
* This class is used to create the client and server gui elements when a player opens a gui. There can only be one gui handler registered per mod,
*   so each GUI is given a unique GuiID which is used to create the correct element.
* The GuiHandlerRegistry is registered with Forge using
* 		NetworkRegistry.INSTANCE.registerGuiHandler(ReferenceMod.instance, new GuiHandlerRegistry());
* Each of the examples, with its own GuiHandler, registers itself with the GuiHandlerRegistry.
* When GuiHandlerRegistry receives a call from Forge, it passes it to the appropriate example's GuiHandler.
*/
public class GuiHandlerRegistry implements IGuiHandler {

public void registerGuiHandler(IGuiHandler hander, int guiID)
{
	registeredHandlers.put(guiID, hander);
}

public static GuiHandlerRegistry getInstance() {return guiHandlerRegistry;}

private HashMap<Integer, IGuiHandler> registeredHandlers = new HashMap<Integer, IGuiHandler>();
private static GuiHandlerRegistry guiHandlerRegistry = new GuiHandlerRegistry();

// Gets the server side element for the given gui id- this should return a container
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	IGuiHandler handler = registeredHandlers.get(ID);
	if (handler != null) {
		return handler.getServerGuiElement(ID, player, world, x, y, z);
	} else {
		return null;
	}
}

// Gets the client side element for the given gui id- this should return a gui
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	IGuiHandler handler = registeredHandlers.get(ID);
	if (handler != null) {
		return handler.getClientGuiElement(ID, player, world, x, y, z);
	} else {
		return null;
	}
}

}

 

package com.rosecotton.shelvesmod;


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;

/**
* User: brandon3055
* Date: 06/01/2015
*
* This class is used to get the client and server gui elements when a player opens a gui. There can only be one registered
*   IGuiHandler instance handler per mod.
*/
public class GuiHandlerShelf implements IGuiHandler {
private static final int GUIID_SHELF = 30;
public static int getGuiID() {    	System.out.println("Called method: GuiHandlerShelf.getGuiID"); return GUIID_SHELF;}


// Gets the server side element for the given gui id- this should return a container
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if (ID != getGuiID()) {
		System.err.println("Invalid ID: expected " + getGuiID() + ", received " + ID);
	}

	BlockPos xyz = new BlockPos(x, y, z);
	TileEntity tileEntity = world.getTileEntity(xyz);
	if (tileEntity instanceof ShelfTitleEntity) {
		ShelfTitleEntity ShelfTitleEntity = (ShelfTitleEntity) tileEntity;
	   	System.out.println("Called method: GuiHandlerShelf.getServerGuiElement return good stuff");
		return new ContainerShelf(player.inventory, ShelfTitleEntity);
	}
    	System.out.println("Called method: GuiHandlerShelf.getServerGuiElement return null");
	return null;
} 

// Gets the client side element for the given gui id- this should return a gui
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if (ID != getGuiID()) {
		System.err.println("Invalid ID: expected " + getGuiID() + ", received " + ID);
	}

	BlockPos xyz = new BlockPos(x, y, z);
	TileEntity tileEntity = world.getTileEntity(xyz);
	if (tileEntity instanceof ShelfTitleEntity) {
		ShelfTitleEntity ShelfTitleEntity = (ShelfTitleEntity) tileEntity;
    	System.out.println("Called method: GuiHandlerShelf.getClientGuiElement return good stuff");
		return new GuiInventoryShelf(player.inventory, ShelfTitleEntity);
	}
    	System.out.println("Called method: GuiHandlerShelf.getClientGuiElement return null");
    	return null;

}
}

 

package com.rosecotton.shelvesmod;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.awt.*;

/**
* User: brandon3055
* Date: 06/01/2015
*
* GuiInventoryShelf is a simple gui that does nothing but draw a background image and a line of text on the screen
* everything else is handled by the vanilla container code
*/
@SideOnly(Side.CLIENT)
public class GuiInventoryShelf extends GuiContainer {

// This is the resource location for the background image for the GUI
private static final ResourceLocation texture = new ResourceLocation("shelvesmod", "textures/gui/shelf_inventory_bg.png");
private ShelfTitleEntity shelfTitleEntity;

public GuiInventoryShelf(InventoryPlayer invPlayer, ShelfTitleEntity tile) {
	super(new ContainerShelf(invPlayer, tile));
	shelfTitleEntity = tile;
	// Set the width and height of the gui.  Should match the size of the texture!
	xSize = 176;
	ySize = 133;
}

// draw the background for the GUI - rendered first
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
	// Bind the image texture of our custom container
	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
	// Draw the image
	GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}

// draw the foreground for the GUI - rendered after the slots, but before the dragged items and tooltips
// renders relative to the top left corner of the background
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
	final int LABEL_XPOS = 5;
	final int LABEL_YPOS = 5;
	fontRendererObj.drawString(shelfTitleEntity.getDisplayName().getUnformattedText(), LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB());
}
}

hw developer in a sw world

Link to comment
Share on other sites

So you have been debugging the thing in your IDE, being able to run the code and everything and did not find it.

Now you throw the code into this forum, not even with syntax highlighting, and expect people to find something?

 

Yeah no. Post a cloneable, working git repo and I might debug it for you.

Link to comment
Share on other sites

Oh, I didn't realize that was an option.

Thank you for the info.

 

I reverted back to my code from Monday, which I'd luckily added to another post and am now backing up...

 

I'll go take another swing at the rendering and see if I come up with the same problem. 

 

Then I'll learn what a working git repo is.  :P

hw developer in a sw world

Link to comment
Share on other sites

Then I'll learn what a working git repo is.  :P

 

www.github.com

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So i just bought a RLcraft server for me and my friends to play on. I launched it and it is working fine but it tells me that i need to download all the mods i go to mods and press "minecraft forge" and nothing shows up that i can open files. If anyone have a suggestion i would need the help. This is the server hosting i  used 
    • i did it in 1.12.2 not walking for me can anyone help me get it pls???  
    • Got the rotation working. I had to look at LivingEntityRenderer#render and setupRotations a little more closely, and I realized that I needed to change the custom entity's yBodyRot and yBodyRotO.  private static boolean renderingCustomEntity = false; private static CustomEntity customEntity; private static void refreshCustomEntity(LocalPlayer localPlayer, LivingEntity livingEntity) { if (customEntity == null || customEntity.isRemoved()) { customEntity = ModEntities.CUSTOM_ENTITY.get().create(localPlayer.clientLevel); } if (!customEntity.level.dimension().equals(livingEntity.level.dimension())) { customEntity.discard(); } } @SubscribeEvent public static void replaceMobModel(RenderLivingEvent.Pre<LivingEntity, EntityModel<LivingEntity>> event) { LocalPlayer localPlayer = Minecraft.getInstance().player; if (localPlayer != null && event.getEntity() instanceof Mob mob) { if (/* put your own condition here */) { if (!renderingCustomEntity) { try { renderingCustomEntity = true; event.setCanceled(true); refreshCustomEntity(localPlayer, mob); // (truth be told, my custom entity does not have a "head", so these lines aren't needed) // customEntity.setYHeadRot(mob.getYHeadRot()); // customEntity.yHeadRotO = mob.yHeadRotO; customEntity.setYBodyRot(mob.yBodyRot); customEntity.yBodyRotO = mob.yBodyRotO; customEntity.setPose(mob.getPose()); Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(customEntity).render( customEntity, customEntity.yBodyRot, event.getPartialTick(), event.getPoseStack(), event.getMultiBufferSource(), event.getPackedLight() ); } finally { renderingCustomEntity = false; } } } } }   As shown in my code, if the mob whose model is replaced moves to a different dimension, I unload the custom entity with Entity#discard and then reinitialize it on the next tick. I wonder if I also have to unload the custom entity when the mob it is "replacing" dies.
    • Thank you for the video, but I found the issue. I had to update the Gradle from 7.2 to 7.3 in gradle/wrapper/gradle-wrapper.properties.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.