Jump to content

DiabolicaTrix

Forge Modder
  • Posts

    48
  • Joined

  • Last visited

Posts posted by DiabolicaTrix

  1. Hi, I've been out of the minecraft ecosystem for a while, so I don't really know any 1.12 server. I want to make my mod compatible with most Economy mods (or Sponge plugins maybe) that are commonly used in servers nowadays. If you know any economy mod/plugin, please let me know!

     

    Thanks!

  2. Hi, I am making a block with an inventory. Currently, hoppers can extract every single item, but I would like to only allow it to extract items from certain slots. I tried to override the extractItem method and only allow extraction for these slots but it also prevents the player from extracting items.

     

    TileEntityShowcase.java: https://gist.github.com/DiabolicaTrix/771fec8aca0f080f9c75d271a5aa1ae5

    TileEntityBase.java: https://gist.github.com/DiabolicaTrix/d849d0b351197871e6a689cc2de048c4

    ItemStackHandlerBase.java: https://gist.github.com/DiabolicaTrix/35cd8e0ebd4b9353069324afcae2f273

    ContainerShowcase.java: https://gist.github.com/DiabolicaTrix/b162d609e1244316fcb1d126546fe81f

    ContainerShowcaseInventory.java: https://gist.github.com/DiabolicaTrix/cea6106842dfcdb70da34a6ae246194d

    SlotShowcase.java: https://gist.github.com/DiabolicaTrix/2b18e4f4ad8dd3307a717e1211aea57c

  3. I did what you asked me and my EntityItem is now in my TE, but that didn't fix my problem. Also, you told me to set the position only once but I can't, that's the reason the item was following me. I found out that the xyz of renderTileEntityAt are dynamic and depends on the position of the player. The animation is not working and I honestly don't know what to do now.

     

     

    TESR:

     

    public class BlockShowcaseTileEntitySpecialRenderer extends TileEntitySpecialRenderer 
    {
    private final Random random = new Random();
    private boolean first = true;
    
    
    public BlockShowcaseTileEntitySpecialRenderer() {}
    
    
    @Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) {
    	EntityItem item = ((BlockShowcaseTileEntity) te).item;
    	ItemStack itemstack = new ItemStack(Items.BAKED_POTATO);
    
    	x += 0.5;
    	y += 0.1;
    	z += 0.5;
    	int i;
    
    
            if (itemstack != null && itemstack.getItem() != null)
            {
                i = Item.getIdFromItem(itemstack.getItem()) + itemstack.getMetadata();
            }
            else
            {
                i = 187;
            }
    
    
            this.random.setSeed((long)i);
    
    
    	boolean flag = false;
    	if (this.bindEntityTexture(item)) {
    		Minecraft.getMinecraft().getRenderManager().renderEngine.getTexture(this.getEntityTexture(item)).setBlurMipmap(false, false);
    		flag = true;
    	}
    	GlStateManager.enableRescaleNormal();
    	GlStateManager.alphaFunc(516, 0.1F);
    	GlStateManager.enableBlend();
    	RenderHelper.enableStandardItemLighting();
    	GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,GlStateManager.DestFactor.ZERO);
    	GlStateManager.pushMatrix();
    	IBakedModel ibakedmodel = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(new ItemStack(Items.BAKED_POTATO), te.getWorld(), (EntityLivingBase) null);
    	int j = this.transformModelCount(item, x, y, z, partialTicks, ibakedmodel);
    
    
    	boolean flag1 = ibakedmodel.isGui3d();
    
    
    
    	if (!flag1) 
    	{ 
    		float f3 = -0.0F * (float)(j - 1) * 0.5F; float f4 = -0.0F * (float)(j - 1) * 0.5F; float f5 = -0.09375F * (float)(j - 1) * 0.5F; 
    		GlStateManager.translate(f3, f4, f5); 
    	}
    
    
    
    	if (flag1) 
    	{
    		GlStateManager.pushMatrix();
    
    
    		ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel,ItemCameraTransforms.TransformType.GROUND, false);
    		Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Items.BAKED_POTATO), ibakedmodel);
    		GlStateManager.popMatrix();
    	} 
    	else 
    	{
    		GlStateManager.pushMatrix();
    
    
    		ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel,ItemCameraTransforms.TransformType.GROUND, false);
    		Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Items.BAKED_POTATO), ibakedmodel);
    		GlStateManager.popMatrix();
    		GlStateManager.translate(0.0F, 0.0F, 0.09375F);
    	}
    
    
    	GlStateManager.popMatrix();
    	GlStateManager.disableRescaleNormal();
    	GlStateManager.disableBlend();
    	this.bindEntityTexture(item);
    
    
    	if (flag) {
    		Minecraft.getMinecraft().renderEngine.getTexture(this.getEntityTexture(item)).restoreLastBlurMipmap();
    	}
    }
    
    
    protected boolean bindEntityTexture(EntityItem entity) {
    	ResourceLocation resourcelocation = this.getEntityTexture(entity);
    
    
    	if (resourcelocation == null) {
    		return false;
    	} else {
    		this.bindTexture(resourcelocation);
    		return true;
    	}
    }
    
    
    protected ResourceLocation getEntityTexture(EntityItem entity) {
    	return TextureMap.LOCATION_BLOCKS_TEXTURE;
    }
    
    
    private int transformModelCount(EntityItem itemIn, double p_177077_2_, double p_177077_4_, double p_177077_6_, float p_177077_8_, IBakedModel p_177077_9_) {
    	ItemStack itemstack = itemIn.getEntityItem();
    	Item item = itemstack.getItem();
    
    
    	if (item == null) {
    		return 0;
    	} else {
    		boolean flag = p_177077_9_.isGui3d();
    		int i = 1;
    		float f = 0.25F;
    		float f1 = shouldBob() ? MathHelper.sin(((float) itemIn.getAge() + p_177077_8_) / 10.0F + itemIn.hoverStart) * 0.1F + 0.1F : 0;
    		float f2 = p_177077_9_.getItemCameraTransforms().getTransform(ItemCameraTransforms.TransformType.GROUND).scale.y;
    		GlStateManager.translate((float) p_177077_2_, (float) p_177077_4_ + f1 + 0.25F * f2, (float) p_177077_6_);
    
    
    		if (flag || Minecraft.getMinecraft().getRenderManager().options != null) {
    			float f3 = (((float) itemIn.getAge() + p_177077_8_) / 20.0F + itemIn.hoverStart) * (180F / (float) Math.PI);
    			GlStateManager.rotate(f3, 0.0F, 1.0F, 0.0F);
    		}
    
    
    		GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    		return i;
    	}
    }
    
    
    public boolean shouldSpreadItems() {
    	return true;
    }
    
    
    public boolean shouldBob() {
    	return true;
    }
    
    
    }
    

     

     

     

    Tile Entity:

    public class BlockShowcaseTileEntity extends TileEntity implements ITickable
    {
    public EntityItem item;
    
    public BlockShowcaseTileEntity()
    {
    	item = new EntityItem(Minecraft.getMinecraft().theWorld, this.pos.getX(), this.pos.getY(), this.pos.getZ(), new ItemStack(Items.BAKED_POTATO));
    }
    
    @Override
    public void update() 
    {
    	if (item.getEntityItem() == null)
            {
                item.setDead();
            }
            else
            {
                item.prevPosX = item.posX;
                item.prevPosY = item.posY;
                item.prevPosZ = item.posZ;
    
    
                if (!item.hasNoGravity())
                {
                	item.motionY -= 0.03999999910593033D;
                }
    
    
                float f = 0.98F;
    
    
                if (item.onGround)
                {
                    f = item.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(item.posX), MathHelper.floor_double(item.getEntityBoundingBox().minY) - 1, MathHelper.floor_double(item.posZ))).getBlock().slipperiness * 0.98F;
                }
    
    
                item.motionX *= (double)f;
                item.motionY *= 0.9800000190734863D;
                item.motionZ *= (double)f;
    
    
                if (item.onGround)
                {
                	item.motionY *= -0.5D;
                }
            }
    }
    }
    

     

    EDIT: Thanks to everyone, I finally found out why the item wasn't moving: the render uses the age of the item to animate it but the age of my item wasn't updating so I just created a int and I add 1 every tick.

  4. So I tried to copy the update method of the EntityItem class and modify it to adapt it to my needs. I also tried to only set the position once but it didn't work, the item is following me and I don't even know why it does. I don't understand why the item is attached to the player but whatever. Also, I don't know if it's related but I can't take screenshots anymore, I'm getting an error:

     

    [20:31:54] [Client thread/ERROR]: ########## GL ERROR ##########
    [20:31:54] [Client thread/ERROR]: @ Pre render
    [20:31:54] [Client thread/ERROR]: 1282: Invalid operation

     

    My code:

     

    private EntityItem item;
       private final Random random = new Random();
       private boolean first = true;
    
    
       public BlockShowcaseTileEntitySpecialRenderer() {
          item = new EntityItem(Minecraft.getMinecraft().theWorld, 0, 0, 0, new ItemStack(Items.BAKED_POTATO));
       }
    
    
       public void update()
       {
            if (item.getEntityItem() == null)
            {
                item.setDead();
            }
            else
            {
                item.prevPosX = item.posX;
                item.prevPosY = item.posY;
                item.prevPosZ = item.posZ;
    
    
                if (!item.hasNoGravity())
                {
                   item.motionY -= 0.03999999910593033D;
                }
    
    
                float f = 0.98F;
    
    
                if (item.onGround)
                {
                    f = item.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(item.posX), MathHelper.floor_double(item.getEntityBoundingBox().minY) - 1, MathHelper.floor_double(item.posZ))).getBlock().slipperiness * 0.98F;
                }
    
    
                item.motionX *= (double)f;
                item.motionY *= 0.9800000190734863D;
                item.motionZ *= (double)f;
    
    
                if (item.onGround)
                {
                   item.motionY *= -0.5D;
                }
            }
       }
       @Override
       public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) {
          ItemStack itemstack = new ItemStack(Items.BAKED_POTATO);
          if(first)
          {
             item.setPosition(x, y, z);
             first = false;
          }
          x = item.posX;
          y = item.posY;
          z = item.posZ;
          z += 0.5;
          y += 0.0;
          z += 0.5;
          int i;
    
    
            if (itemstack != null && itemstack.getItem() != null)
            {
                i = Item.getIdFromItem(itemstack.getItem()) + itemstack.getMetadata();
            }
            else
            {
                i = 187;
            }
    
    
            this.random.setSeed((long)i);
    
    
          boolean flag = false;
          if (this.bindEntityTexture(item)) {
             Minecraft.getMinecraft().getRenderManager().renderEngine.getTexture(this.getEntityTexture(item)).setBlurMipmap(false, false);
             flag = true;
          }
          GlStateManager.enableRescaleNormal();
          GlStateManager.alphaFunc(516, 0.1F);
          GlStateManager.enableBlend();
          RenderHelper.enableStandardItemLighting();
          GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,GlStateManager.DestFactor.ZERO);
          GlStateManager.pushMatrix();
          IBakedModel ibakedmodel = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(new ItemStack(Items.BAKED_POTATO), te.getWorld(), (EntityLivingBase) null);
          int j = this.transformModelCount(item, x, y, z, partialTicks, ibakedmodel);
    
    
          boolean flag1 = ibakedmodel.isGui3d();
    
    
          
          if (!flag1) 
          { 
             float f3 = -0.0F * (float)(j - 1) * 0.5F; float f4 = -0.0F * (float)(j - 1) * 0.5F; float f5 = -0.09375F * (float)(j - 1) * 0.5F; 
             GlStateManager.translate(f3, f4, f5); 
          }
           
    
    
          if (flag1) 
          {
             GlStateManager.pushMatrix();
    
    
             ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel,ItemCameraTransforms.TransformType.GROUND, false);
             Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Items.BAKED_POTATO), ibakedmodel);
             GlStateManager.popMatrix();
          } 
          else 
          {
             GlStateManager.pushMatrix();
    
    
             ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel,ItemCameraTransforms.TransformType.GROUND, false);
             Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Items.BAKED_POTATO), ibakedmodel);
             GlStateManager.popMatrix();
             GlStateManager.translate(0.0F, 0.0F, 0.09375F);
          }
    
    
          GlStateManager.popMatrix();
          GlStateManager.disableRescaleNormal();
          GlStateManager.disableBlend();
          this.bindEntityTexture(item);
    
    
          if (flag) {
             Minecraft.getMinecraft().renderEngine.getTexture(this.getEntityTexture(item)).restoreLastBlurMipmap();
          }
          
          this.update();
       }
    
    
       protected boolean bindEntityTexture(EntityItem entity) {
          ResourceLocation resourcelocation = this.getEntityTexture(entity);
    
    
          if (resourcelocation == null) {
             return false;
          } else {
             this.bindTexture(resourcelocation);
             return true;
          }
       }
    
    
       protected ResourceLocation getEntityTexture(EntityItem entity) {
          return TextureMap.LOCATION_BLOCKS_TEXTURE;
       }
    
    
       private int transformModelCount(EntityItem itemIn, double p_177077_2_, double p_177077_4_, double p_177077_6_, float p_177077_8_, IBakedModel p_177077_9_) {
          ItemStack itemstack = itemIn.getEntityItem();
          Item item = itemstack.getItem();
    
    
          if (item == null) {
             return 0;
          } else {
             boolean flag = p_177077_9_.isGui3d();
             int i = 1;
             float f = 0.25F;
             float f1 = shouldBob() ? MathHelper.sin(((float) itemIn.getAge() + p_177077_8_) / 10.0F + itemIn.hoverStart) * 0.1F + 0.1F : 0;
             float f2 = p_177077_9_.getItemCameraTransforms().getTransform(ItemCameraTransforms.TransformType.GROUND).scale.y;
             GlStateManager.translate((float) p_177077_2_, (float) p_177077_4_ + f1 + 0.25F * f2, (float) p_177077_6_);
    
    
             if (flag || Minecraft.getMinecraft().getRenderManager().options != null) {
                float f3 = (((float) itemIn.getAge() + p_177077_8_) / 20.0F + itemIn.hoverStart) * (180F / (float) Math.PI);
                GlStateManager.rotate(f3, 0.0F, 1.0F, 0.0F);
             }
    
    
             GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
             return i;
          }
       }
    
    
       public boolean shouldSpreadItems() {
          return true;
       }
    
    
       public boolean shouldBob() {
          return true;
       }

     

     

     

    Screenshot:

    484af53a84962dc122f6eb2f48cb3347.png

     

  5. Ok, so I tried to look into the RenderEntityItem to see how they animate the entity but I couldn't find anything about the animation. Now, my item is rendering in the block but the problem is that it's shacking. It looks like the item is trying to animate but the position is reset every tick so I guess the animation is achieved by modifying the x y z but I couldn't find where the doRender function is called. Any ideas?

     

     

    My code:

     

    private EntityItem item;
       private final Random random = new Random();
    
    
       public BlockShowcaseTileEntitySpecialRenderer() {
          item = new EntityItem(Minecraft.getMinecraft().theWorld, 0, 0, 0, new ItemStack(Items.BAKED_POTATO));
       }
    
    
       @Override
       public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) {
          ItemStack itemstack = new ItemStack(Items.BAKED_POTATO);
          x += 0.5;
          y += 0.0;
          z += 0.5;
          
          int i;
    
    
            if (itemstack != null && itemstack.getItem() != null)
            {
                i = Item.getIdFromItem(itemstack.getItem()) + itemstack.getMetadata();
            }
            else
            {
                i = 187;
            }
    
    
            this.random.setSeed((long)i);
    
    
          boolean flag = false;
          if (this.bindEntityTexture(item)) {
             Minecraft.getMinecraft().getRenderManager().renderEngine.getTexture(this.getEntityTexture(item)).setBlurMipmap(false, false);
             flag = true;
          }
          GlStateManager.enableRescaleNormal();
          GlStateManager.alphaFunc(516, 0.1F);
          GlStateManager.enableBlend();
          RenderHelper.enableStandardItemLighting();
          GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,GlStateManager.DestFactor.ZERO);
          GlStateManager.pushMatrix();
          IBakedModel ibakedmodel = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(new ItemStack(Items.BAKED_POTATO), te.getWorld(), (EntityLivingBase) null);
          int j = this.transformModelCount(item, x, y, z, partialTicks, ibakedmodel);
    
    
          boolean flag1 = ibakedmodel.isGui3d();
    
    
          
          if (!flag1) 
          { 
             float f3 = -0.0F * (float)(j - 1) * 0.5F; float f4 = -0.0F * (float)(j - 1) * 0.5F; float f5 = -0.09375F * (float)(j - 1) * 0.5F; 
             GlStateManager.translate(f3, f4, f5); 
          }
           
    
    
          if (flag1) 
          {
             GlStateManager.pushMatrix();
    
    
             ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel,ItemCameraTransforms.TransformType.GROUND, false);
             Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Items.BAKED_POTATO), ibakedmodel);
             GlStateManager.popMatrix();
          } 
          else 
          {
             GlStateManager.pushMatrix();
    
    
             ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel,ItemCameraTransforms.TransformType.GROUND, false);
             Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Items.BAKED_POTATO), ibakedmodel);
             GlStateManager.popMatrix();
             GlStateManager.translate(0.0F, 0.0F, 0.09375F);
          }
    
    
          GlStateManager.popMatrix();
          GlStateManager.disableRescaleNormal();
          GlStateManager.disableBlend();
          this.bindEntityTexture(item);
    
    
          if (flag) {
             Minecraft.getMinecraft().renderEngine.getTexture(this.getEntityTexture(item)).restoreLastBlurMipmap();
          }
       }
    
    
       protected boolean bindEntityTexture(EntityItem entity) {
          ResourceLocation resourcelocation = this.getEntityTexture(entity);
    
    
          if (resourcelocation == null) {
             return false;
          } else {
             this.bindTexture(resourcelocation);
             return true;
          }
       }
    
    
       protected ResourceLocation getEntityTexture(EntityItem entity) {
          return TextureMap.LOCATION_BLOCKS_TEXTURE;
       }
    
    
       private int transformModelCount(EntityItem itemIn, double p_177077_2_, double p_177077_4_, double p_177077_6_, float p_177077_8_, IBakedModel p_177077_9_) {
          ItemStack itemstack = itemIn.getEntityItem();
          Item item = itemstack.getItem();
    
    
          if (item == null) {
             return 0;
          } else {
             boolean flag = p_177077_9_.isGui3d();
             int i = 1;
             float f = 0.25F;
             float f1 = shouldBob() ? MathHelper.sin(((float) itemIn.getAge() + p_177077_8_) / 10.0F + itemIn.hoverStart) * 0.1F + 0.1F : 0;
             float f2 = p_177077_9_.getItemCameraTransforms().getTransform(ItemCameraTransforms.TransformType.GROUND).scale.y;
             GlStateManager.translate((float) p_177077_2_, (float) p_177077_4_ + f1 + 0.25F * f2, (float) p_177077_6_);
    
    
             if (flag || Minecraft.getMinecraft().getRenderManager().options != null) {
                float f3 = (((float) itemIn.getAge() + p_177077_8_) / 20.0F + itemIn.hoverStart) * (180F / (float) Math.PI);
                GlStateManager.rotate(f3, 0.0F, 1.0F, 0.0F);
             }
    
    
             GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
             return i;
          }
       }
    
    
       public boolean shouldSpreadItems() {
          return true;
       }
    
    
       public boolean shouldBob() {
          return true;
       }

     

     

     

    What it looks like:

  6. Ok so I looked at the RenderEntityItem class and tried to make something from this.

     

     

    What it looks like:

    1cc72b636752b15dbf8731127f404a49.png

     

     

    Tesr:

    public class BlockShowcaseTileEntitySpecialRenderer extends TileEntitySpecialRenderer 
    {
       private EntityItem item;
       private final Random random = new Random();
       
       public BlockShowcaseTileEntitySpecialRenderer() 
       {
          item = new EntityItem(Minecraft.getMinecraft().theWorld, 0, 0, 0, new ItemStack(Items.APPLE));
       }
       
       @Override
       public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) 
       {
          boolean flag = false;
          if (this.bindEntityTexture(item))
            {
                Minecraft.getMinecraft().getRenderManager().renderEngine.getTexture(this.getEntityTexture(item)).setBlurMipmap(false, false);
                flag = true;
            }
          GlStateManager.enableRescaleNormal();
            GlStateManager.alphaFunc(516, 0.1F);
            GlStateManager.enableBlend();
            RenderHelper.enableStandardItemLighting();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            GlStateManager.pushMatrix();
           IBakedModel ibakedmodel = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(new ItemStack(Items.APPLE), te.getWorld(), (EntityLivingBase)null);
           int j = this.transformModelCount(item, x, y, z, partialTicks, ibakedmodel);
           
           boolean flag1 = ibakedmodel.isGui3d();
    
            if (!flag1)
            {
                float f3 = -0.0F * (float)(j - 1) * 0.5F;
                float f4 = -0.0F * (float)(j - 1) * 0.5F;
                float f5 = -0.09375F * (float)(j - 1) * 0.5F;
                GlStateManager.translate(f3, f4, f5);
            }
            
            for (int k = 0; k < j; ++k)
            {
                if (flag1)
                {
                    GlStateManager.pushMatrix();
    
                    if (k > 0)
                    {
                        float f7 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
                        float f9 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
                        float f6 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
                        GlStateManager.translate(shouldSpreadItems() ? f7 : 0, shouldSpreadItems() ? f9 : 0, f6);
                    }
    
                    ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel, ItemCameraTransforms.TransformType.GROUND, false);
                    Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Items.APPLE), ibakedmodel);
                    GlStateManager.popMatrix();
                }
                else
                {
                    GlStateManager.pushMatrix();
    
                    if (k > 0)
                    {
                        float f8 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F * 0.5F;
                        float f10 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F * 0.5F;
                        GlStateManager.translate(f8, f10, 0.0F);
                    }
    
                    ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel, ItemCameraTransforms.TransformType.GROUND, false);
                    Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Items.APPLE), ibakedmodel);
                    GlStateManager.popMatrix();
                    GlStateManager.translate(0.0F, 0.0F, 0.09375F);
                }
            }
            
            GlStateManager.popMatrix();
            GlStateManager.disableRescaleNormal();
            GlStateManager.disableBlend();
            this.bindEntityTexture(item);
    
            if (flag)
            {
               Minecraft.getMinecraft().renderEngine.getTexture(this.getEntityTexture(item)).restoreLastBlurMipmap();
            }
       }
       
       protected boolean bindEntityTexture(EntityItem entity)
        {
            ResourceLocation resourcelocation = this.getEntityTexture(entity);
    
            if (resourcelocation == null)
            {
                return false;
            }
            else
            {
                this.bindTexture(resourcelocation);
                return true;
            }
        }
       
       protected ResourceLocation getEntityTexture(EntityItem entity)
        {
            return TextureMap.LOCATION_BLOCKS_TEXTURE;
        }
       
       private int transformModelCount(EntityItem itemIn, double p_177077_2_, double p_177077_4_, double p_177077_6_, float p_177077_8_, IBakedModel p_177077_9_)
        {
            ItemStack itemstack = itemIn.getEntityItem();
            Item item = itemstack.getItem();
    
            if (item == null)
            {
                return 0;
            }
            else
            {
                boolean flag = p_177077_9_.isGui3d();
                int i = 1;
                float f = 0.25F;
                float f1 = shouldBob() ? MathHelper.sin(((float)itemIn.getAge() + p_177077_8_) / 10.0F + itemIn.hoverStart) * 0.1F + 0.1F : 0;
                float f2 = p_177077_9_.getItemCameraTransforms().getTransform(ItemCameraTransforms.TransformType.GROUND).scale.y;
                GlStateManager.translate((float)p_177077_2_, (float)p_177077_4_ + f1 + 0.25F * f2, (float)p_177077_6_);
    
                if (flag || Minecraft.getMinecraft().getRenderManager().options != null)
                {
                    float f3 = (((float)itemIn.getAge() + p_177077_8_) / 20.0F + itemIn.hoverStart) * (180F / (float)Math.PI);
                    GlStateManager.rotate(f3, 0.0F, 1.0F, 0.0F);
                }
    
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                return i;
            }
        }
       
        public boolean shouldSpreadItems()
        {
            return true;
        }
    
        public boolean shouldBob()
        {
            return true;
        }
       
    }

     

     

    Even if the apple is dark, we can see that the texture is applied. Also, I can't show you with a picture but the apple is shaking a bit. It looks like it's trying to rotate but due to the fact that the function is called every tick, the position is reset. I should be able to fix this by myself but I'm going to need help to fix the color of the apple as I don't even know where to look.

  7. I would you do that? I created a new instance of EntityItem but how do I render it? I never did this before, sorry if it seems obvious to you.

     

     

     

    	EntityItem item;
    
    public BlockShowcaseTileEntitySpecialRenderer() 
    {
    	item = new EntityItem(Minecraft.getMinecraft().theWorld, 0, 0, 0, new ItemStack(Items.APPLE));
    }
    
    @Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) 
    {
    	item.setPosition(x + 0.5, y + 0.1, z + 0.5);
        GlStateManager.pushMatrix();
        
        GlStateManager.popMatrix();
    }

     

  8. Hi, I'm trying to make a transparent block with an item inside. I want the item to have the same animation as a dropped item. I made the model and a tesr for it so I can render the item but I have no clue how do what I want. I tried looking into the TileEntityItemStackRenderer class to see how they are rendering the items on the ground (I believe it's the right class) and the only thing I found is this line:

     

     

                else if (block != Blocks.CHEST) net.minecraftforge.client.ForgeHooksClient.renderTileItem(itemStackIn.getItem(), itemStackIn.getMetadata());
    

     

     

    So I went into the ForgeHooksClient class and found the above function but I couldn't find where the render is done.

     

     

    An image of the block:

     

    315b0b3be1c2b53cbf2a9c1e4fd4242b.png

     

     

     

    My classes:

     

    Block:

     

    package com.wartimepvp.blocks;
    
    
    import com.wartimepvp.tileentities.BlockShowcaseTileEntity;
    
    
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockContainer;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.BlockRenderLayer;
    import net.minecraft.util.EnumBlockRenderType;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    
    public class BlockShowcase extends BlockContainer 
    {
    
    
       public BlockShowcase(Material material) 
       {
          super(material);
          this.setResistance(5.0F);
          this.setHardness(1.0F);
          this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
       }
       
       @SideOnly(Side.CLIENT)
        public BlockRenderLayer getBlockLayer()
        {
            return BlockRenderLayer.CUTOUT;
        }
       
       @Override
       public boolean isOpaqueCube(IBlockState state)
        {
            return false;
        }
       
       @Override
       public EnumBlockRenderType getRenderType(IBlockState state)
        {
            return EnumBlockRenderType.MODEL;
        }
    
    
        public boolean isFullCube(IBlockState state)
        {
            return true;
        }
    
    
       @Override
       public TileEntity createNewTileEntity(World worldIn, int meta) {
          return new BlockShowcaseTileEntity();
       }
    
    
    }
    

     

     

     

     

    TileEntitySpecialRenderer:

     

    package com.wartimepvp.tesr;
    
    
    import net.minecraft.client.renderer.GlStateManager;
    import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
    import net.minecraft.tileentity.TileEntity;
    
    
    public class BlockShowcaseTileEntitySpecialRenderer extends TileEntitySpecialRenderer 
    {
       @Override
       public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) 
       {
           GlStateManager.pushMatrix();
           GlStateManager.translate(x, y + 0.2, z);
    
    
           GlStateManager.popMatrix();
       }
    }
    

     

  9.  

    Like that? 

    @Override
        public NBTTagCompound serializeNBT()
        {
            NBTTagCompound compound = new NBTTagCompound();
            compound.setInteger("Test", this.getTest());
            return compound;
        }
    
    
        @Override
        public void deserializeNBT(NBTTagCompound compound)
        {
            this.setTest(compound.getInteger("Test"));    }

  10.     public static class Storage implements Capability.IStorage<PlayerCapabilities>
        {
    
    
            @Override
            public NBTBase writeNBT(Capability<PlayerCapabilities> capability, PlayerCapabilities instance, EnumFacing side)
            {
                NBTTagCompound compound = new NBTTagCompound();
                
                compound.setInteger("Test", instance.getTest());
                
                return compound;
            }
    
    
            @Override
            public void readNBT(Capability<PlayerCapabilities> capability, PlayerCapabilities instance, EnumFacing side, NBTBase nbt)
            {
                NBTTagCompound compound = (NBTTagCompound) nbt;
                
                instance.setTest(compound.getInteger("Test"));
            }
    
        }

  11. It's doing exactly what I said before:

     

     

     

    [16:43:24] [server thread/INFO] [sTDOUT]: [me.diabolicatrix.events.CommonEventHandler:onAttachCapability:62]: Attach Server

    [16:43:24] [Netty Local Client IO #1/INFO] [sTDOUT]: [me.diabolicatrix.packets.PacketSyncCapabilities$ClientHandler:onMessage:58]: Packet Received

    [16:43:24] [Client thread/INFO] [sTDOUT]: [me.diabolicatrix.events.CommonEventHandler:onAttachCapability:62]: Attach Client

  12. Sorry, I misexplained. The AttachCapabilitiesEvent is called before the PlayerCloneEvent on client-side but it works on server-side.

     

     

     

    [15:30:19] [server thread/INFO] [sTDOUT]: [me.diabolicatrix.events.CommonEventHandler:onAttachCapability:62]: Attach Server

    [15:30:19] [server thread/INFO] [sTDOUT]: [me.diabolicatrix.events.CommonEventHandler:onPlayerCloned:49]: Clone (server only)

    [15:30:19] [Client thread/INFO] [sTDOUT]: [me.diabolicatrix.events.CommonEventHandler:onAttachCapability:62]: Attach Client

     

     

    So even if I try to sync with a packet, the value will be overwritten by the attach event.

×
×
  • Create New...

Important Information

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