Jump to content

[SOLVED]TileRender not rendering item. Returning null on value retrieving.


ItsMartNotMert

Recommended Posts

So I have a render class for my tileentity that is supposed to render the item put in the tileEntity. The item is there but the function to retrieve the item doesnt seem to work right.

 

Heres my TileEntity Class:

 

package com.mart.solar.tileentities;

import com.google.common.collect.BiMap;
import com.mart.solar.items.ItemRune;
import com.mart.solar.recipes.InfuserRecipeRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;

public class TileRuneInfuser extends TileEntity {

    private ItemStack rune;
    private ItemStack modifier;


    public void onUse(ItemStack heldItem, EntityPlayer player, EnumHand hand){
        if(heldItem.getItem() instanceof ItemRune){
            if(rune == null){
                ItemStack heldItem2 = heldItem.copy();

                heldItem2.stackSize = 1;
                setRune(heldItem2);

                heldItem.stackSize--;
                player.setHeldItem(hand, heldItem);
                System.out.println("Rune Added");
            }
        }
        else{
            if(modifier == null){
                ItemStack heldItem2 = heldItem.copy();

                heldItem2.stackSize = 1;
                setModifier(heldItem2);

                heldItem.stackSize--;
                player.setHeldItem(hand, heldItem);
                System.out.println("Modifier Added");
            }
        }

        checkRecipe();
    }

    public void extractItem(EntityPlayer player, EnumHand hand){
        if(modifier != null){
            player.inventory.addItemStackToInventory(modifier);
            System.out.println("Modifier Extracted:" + modifier.getDisplayName());
            setModifier(null);
        }
        else if(rune != null) {
            player.inventory.addItemStackToInventory(rune);
            setRune(null);
            System.out.println("Rune Extraced");
        }
    }

    public void checkRecipe(){
        if(rune != null && modifier != null){
            for(BiMap.Entry<Item, InfuserRecipeRegister.InfuserRecipe> b : InfuserRecipeRegister.getRecipes().entrySet()){
                if(modifier.getItem() == b.getKey()){

                    ItemStack output = new ItemStack(b.getValue().getOutput(), 1);
                    setModifier(output);
                    System.out.println("Output Set to: " + output.getDisplayName());

                    setRune(null);


                    System.out.println("Rune Removed");
                    return;
                }
            }
        }
    }


    public ItemStack getModifier() {
        return modifier;
    }

    public Item getMod(){
        if(modifier != null){
            return modifier.getItem();
        }
        return null;
    }

    public void setModifier(ItemStack modifier2) {
        this.modifier = modifier2;
    }

    public ItemStack getRune() {

        return rune;
    }

    public void setRune(ItemStack rune) {
        this.rune = rune;
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        super.writeToNBT(compound);

        if(rune != null){
            NBTTagList tagList = new NBTTagList();
            NBTTagCompound itemCompound = new NBTTagCompound();
            rune.writeToNBT(itemCompound);
            tagList.appendTag(itemCompound);
            compound.setTag("rune", tagList);
        }

        if(modifier != null){
            NBTTagList itemList = new NBTTagList();
            NBTTagCompound modifierCompound = new NBTTagCompound();
            modifier.writeToNBT(modifierCompound);
            itemList.appendTag(modifierCompound);
            compound.setTag("modifier", itemList);
        }

        return compound;
    }

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);

            NBTTagList tagList = (NBTTagList) compound.getTag("rune");
            NBTTagCompound tagCompound = tagList.getCompoundTagAt(0);
            rune = ItemStack.loadItemStackFromNBT(tagCompound);


            NBTTagList modifierList = (NBTTagList) compound.getTag("modifier");
            NBTTagCompound modifierCompound = modifierList.getCompoundTagAt(0);
            modifier = ItemStack.loadItemStackFromNBT(modifierCompound);


    }
}

 

 

My render class:

 

package com.mart.solar.client.render;

import com.mart.solar.tileentities.TileRuneInfuser;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class RenderInfuser extends TileEntitySpecialRenderer<TileRuneInfuser> {

    public static Minecraft mc = Minecraft.getMinecraft();

    @Override
    public void renderTileEntityAt(TileRuneInfuser runeInfuser, double x, double y, double z, float partialTicks, int destroyStage)
    {
        ItemStack inputStack =  runeInfuser.getRune();

        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, z);
        this.renderItem(runeInfuser.getWorld(), inputStack, partialTicks);
        GlStateManager.popMatrix();



    }

    private void renderItem(World world, ItemStack stack, float partialTicks)
    {
        RenderItem itemRenderer = mc.getRenderItem();
        if (stack != null)
        {
            System.out.println("Called");
            GlStateManager.translate(0.5, 1, 0.5);
            EntityItem entityitem = new EntityItem(world, 0.0D, 0.0D, 0.0D, stack);
            entityitem.getEntityItem().stackSize = 1;
            entityitem.hoverStart = 0.0F;
            GlStateManager.pushMatrix();
            GlStateManager.disableLighting();

            float rotation = (float) (720.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);

            GlStateManager.rotate(rotation, 0.0F, 1.0F, 0);
            GlStateManager.scale(0.5F, 0.5F, 0.5F);
            GlStateManager.pushAttrib();
            RenderHelper.enableStandardItemLighting();
            itemRenderer.renderItem(entityitem.getEntityItem(), ItemCameraTransforms.TransformType.FIXED);
            RenderHelper.disableStandardItemLighting();
            GlStateManager.popAttrib();

            GlStateManager.enableLighting();
            GlStateManager.popMatrix();
        }
    }


}

 

 

Block class:

 

package com.mart.solar.blocks;

import com.mart.solar.Solar;
import com.mart.solar.tileentities.TileRuneInfuser;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import javax.annotation.Nullable;

public class BlockRuneInfuser extends BlockBase implements ITileEntityProvider {

    public BlockRuneInfuser(String name) {
        super(Material.WOOD, name);
        setCreativeTab(Solar.solarTab);
    }

    @Override
    @Deprecated
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

    @Override
    public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos)
    {
        return false;
    }


    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
        if(!world.isRemote) {
            if(hand.equals(EnumHand.MAIN_HAND)){
                TileRuneInfuser tileEntity = (TileRuneInfuser)world.getTileEntity(pos);

                if (tileEntity == null || player.isSneaking())
                    return false;

                if (heldItem != null){
                    tileEntity.onUse(heldItem, player, hand);
                }
                else{
                    player.swingArm(hand);
                    tileEntity.extractItem(player, hand);
                }
            }
        }
        return true;
    }

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

 

 

Blockstate:

 

{
  "forge_marker": 1,
  "defaults": {
    "textures": {
      "all": "solar:blocks/runeInfuser"
    }
  },
  "variants": {
    "normal": {
      "model": "cube_all"
    },
    "inventory": {
      "model": "cube_all"
    }
  }
}

 

 

The item is set because I can also retrieve it, but it returns null to the Render class.. any idea on whats causing this?

Link to comment
Share on other sites

Something something something getUpdatePacket

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

It's so stupidly hilarious how easy this is to figure out I'll both link it to you and laugh.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/ores/entities/TileEntitySifter.java#L151-L160

A hahahaha

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