Jump to content

Recommended Posts

Posted

Whenever I connect the world, rendering disappears. When I click on the block to appear.

 

TileEntity:

 

 

package cz.grossik.farmcraft2.racks;

 

import javax.annotation.Nullable;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.ISidedInventory;

import net.minecraft.inventory.ItemStackHelper;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.tileentity.TileEntityLockable;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.ITickable;

 

public class TileEntityRacks extends TileEntityLockable implements ITickable, ISidedInventory

{

    private ItemStack[] wineItemStacks = new ItemStack[9];

    private String furnaceCustomName;

    private NBTTagCompound update_packet;

   

    private boolean Check0;

   

    public int getSizeInventory()

    {

        return this.wineItemStacks.length;

    }

 

    public ItemStack getStackInSlot(int index)

    {

        return this.wineItemStacks[index];

    }

 

    @Nullable

    public ItemStack decrStackSize(int index, int count)

    {

        return ItemStackHelper.getAndSplit(this.wineItemStacks, index, count);

    }

 

    @Nullable

    public ItemStack removeStackFromSlot(int index)

    {

        return ItemStackHelper.getAndRemove(this.wineItemStacks, index);

    }

 

    public void setCustomInventoryName(String p_145951_1_)

    {

        this.furnaceCustomName = p_145951_1_;

    }

 

    public void setInventorySlotContents(int index, ItemStack stack)

    {

        boolean flag = stack != null && stack.isItemEqual(this.wineItemStacks[index]) && ItemStack.areItemStackTagsEqual(stack, this.wineItemStacks[index]);

        this.wineItemStacks[index] = stack;

 

        if (stack != null && stack.stackSize > this.getInventoryStackLimit())

        {

            stack.stackSize = this.getInventoryStackLimit();

        }

    }

 

 

@Override

public int getInventoryStackLimit() {

return 1;

}

 

    public void readFromNBT(NBTTagCompound compound)

    {

        super.readFromNBT(compound);

        NBTTagList nbttaglist = compound.getTagList("Items", 10);

        this.wineItemStacks = new ItemStack[this.getSizeInventory()];

       

        for (int i = 0; i < nbttaglist.tagCount(); ++i)

        {

            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);

            int j = nbttagcompound.getByte("Slot");

 

            if (j >= 0 && j < this.wineItemStacks.length)

            {

                this.wineItemStacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);

            }

        }

       

        if (compound.hasKey("CustomName", 8))

        {

            this.furnaceCustomName = compound.getString("CustomName");

        }

    }

 

    public NBTTagCompound writeToNBT(NBTTagCompound compound)

    {

        super.writeToNBT(compound);

        NBTTagList nbttaglist = new NBTTagList();

       

        for (int i = 0; i < this.wineItemStacks.length; ++i)

        {

            if (this.wineItemStacks != null)

            {

                NBTTagCompound nbttagcompound = new NBTTagCompound();

                nbttagcompound.setByte("Slot", (byte)i);

                this.wineItemStacks.writeToNBT(nbttagcompound);

                nbttaglist.appendTag(nbttagcompound);

            }

        }

               

        compound.setTag("Items", nbttaglist);

 

        if (this.hasCustomName())

        {

            compound.setString("CustomName", this.furnaceCustomName);

        }

return compound;

    }

   

    public boolean isUseableByPlayer(EntityPlayer player)

    {

        return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;

    }

 

 

    public void openInventory(EntityPlayer player)

    {

    }

 

    public void closeInventory(EntityPlayer player)

    {

    }

 

public boolean isItemValidForSlot(int index, ItemStack stack) {

return false;

}

 

@Override

public int getField(int id) {

return 0;

}

 

@Override

public void setField(int id, int value) {

}

 

@Override

public int getFieldCount() {

return 0;

}

 

    public void clear()

    {

        for (int i = 0; i < this.wineItemStacks.length; ++i)

        {

            this.wineItemStacks = null;

        }

    }

 

public String getName() {

        return this.hasCustomName() ? this.furnaceCustomName : "Racks";

}

 

    public boolean hasCustomName()

    {

        return this.furnaceCustomName != null && !this.furnaceCustomName.isEmpty();

    }

 

@Override

public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {

        return new ContainerRacks(playerInventory, this);

}

 

@Override

public String getGuiID() {

return "10";

}

 

@Override

public int[] getSlotsForFace(EnumFacing side) {

return null;

}

 

@Override

public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {

        return this.isItemValidForSlot(index, itemStackIn);

}

 

public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {

        return true;

}

 

@Override

public void update() {       

}

 

    public boolean Check0(){ 

    if(wineItemStacks[0] != null)

    {

    return true;

    } else {

    return false;

    }

    }

   

    public boolean Check1(){ 

    if(wineItemStacks[1] != null)

    {

    return true;

    } else {

    return false;

    }

    } 

 

    public boolean Check2(){ 

    if(wineItemStacks[2] != null)

    {

    return true;

    } else {

    return false;

    }

    } 

   

    public boolean Check3(){ 

    if(wineItemStacks[3] != null)

    {

    return true;

    } else {

    return false;

    }

    } 

   

    public boolean Check4(){ 

    if(wineItemStacks[4] != null)

    {

    return true;

    } else {

    return false;

    }

    } 

   

    public boolean Check5(){ 

    if(wineItemStacks[5] != null)

    {

    return true;

    } else {

    return false;

    }

    } 

   

    public boolean Check6(){ 

    if(wineItemStacks[6] != null)

    {

    return true;

    } else {

    return false;

    }

    } 

   

    public boolean Check7(){ 

    if(wineItemStacks[7] != null)

    {

    return true;

    } else {

    return false;

    }

    } 

   

    public boolean Check8(){ 

    if(wineItemStacks[8] != null)

    {

    return true;

    } else {

    return false;

    }

    } 

}

 

 

 

Render:

 

 

package cz.grossik.farmcraft2.racks;

 

import cz.grossik.farmcraft2.Main;

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

@SideOnly(Side.CLIENT)

public class RenderRacks extends TileEntitySpecialRenderer<TileEntityRacks>

{

    private static final ModelWine0 model0 = new ModelWine0();

    private static final ModelWine1 model1 = new ModelWine1();

    private static final ModelWine2 model2 = new ModelWine2();   

    private static final ModelWine3 model3 = new ModelWine3();

    private static final ModelWine4 model4 = new ModelWine4();

    private static final ModelWine5 model5 = new ModelWine5();

    private static final ModelWine6 model6 = new ModelWine6();

    private static final ModelWine7 model7 = new ModelWine7();

    private static final ModelWine8 model8 = new ModelWine8();

 

    private static final ResourceLocation tWine = new ResourceLocation(Main.MODID + ":textures/wine.png");

 

    @Override

    public void renderTileEntityAt(TileEntityRacks te, double x, double y, double z, float partialTicks, int destroyStage)

    {

        GlStateManager.pushAttrib();

        GlStateManager.pushMatrix();

        GlStateManager.translate(x, y, z + 0.5f);

        ResourceLocation texture0 = tWine;

   

        bindTexture(texture0);

       

        if(te.Check0() == true) { model0.render(); }

       

        if(te.Check1() == true) { model1.render(); }

       

        if(te.Check2() == true) { model2.render(); }

 

        if(te.Check3() == true) { model3.render(); }

 

        if(te.Check4() == true) { model4.render(); }

       

        if(te.Check5() == true) { model5.render(); }

 

        if(te.Check6() == true) { model6.render(); }

 

        if(te.Check7() == true) { model7.render(); }

 

        if(te.Check8() == true) { model8.render(); }

       

        GlStateManager.popMatrix();

        GlStateManager.popAttrib();

    }

}

 

 

 

Sorry for my bad English.

Posted

You need to override TileEntity#getUpdatePacket(), TileEntity#getUpdateTag(), TileEntity#onDataPacket(), and TileEntity#handleUpdateTag(). And you should switch fromusing ISIdedInventory to the IItemHandler capability.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

What? I don't know how to override it.

This is the support section for those modding with Forge. Help with modding goes in here, however, please keep in mind that this is not a Java school. You are expected to have basic knowledge of Java before posting here.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

I figured it out myself.

 

package cz.grossik.farmcraft2.racks;

import javax.annotation.Nullable;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntityLockable;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper;

public class TileEntityRacks extends TileEntityLockable implements ITickable, ISidedInventory
{
    private ItemStack[] wineItemStacks = new ItemStack[9];
    private String furnaceCustomName;
    private NBTTagCompound update_packet;
        
    public int getSizeInventory()
    {
        return this.wineItemStacks.length;
    }

    public ItemStack getStackInSlot(int index)
    {
        return this.wineItemStacks[index];
    }

    @Nullable
    public ItemStack decrStackSize(int index, int count)
    {
        return ItemStackHelper.getAndSplit(this.wineItemStacks, index, count);
    }

    @Nullable
    public ItemStack removeStackFromSlot(int index)
    {
        return ItemStackHelper.getAndRemove(this.wineItemStacks, index);
    }

    public void setCustomInventoryName(String p_145951_1_)
    {
        this.furnaceCustomName = p_145951_1_;
    }

    public void setInventorySlotContents(int index, ItemStack stack)
    {
        boolean flag = stack != null && stack.isItemEqual(this.wineItemStacks[index]) && ItemStack.areItemStackTagsEqual(stack, this.wineItemStacks[index]);
        this.wineItemStacks[index] = stack;

        if (stack != null && stack.stackSize > this.getInventoryStackLimit())
        {
            stack.stackSize = this.getInventoryStackLimit();
        }
    }


@Override
public int getInventoryStackLimit() {
	return 1;
}

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

    int i;

    for(i = 0; i < getSizeInventory(); i++)
    {
      NBTTagCompound tag = (NBTTagCompound)compound.getTag("Item_" + String.valueOf(i));
      if(tag != null)
      {
        ItemStack stack = null;
        if(!tag.getBoolean("empty"))
        {
          stack = ItemStack.loadItemStackFromNBT(tag);
        }
        wineItemStacks[i] = stack;
      }
    }
  }

  protected final void updateInventoryItem(int slot)
  {
    if(worldObj.isRemote)
    {
      return;
    }
    if(update_packet == null)
    {
      update_packet = new NBTTagCompound();
      super.writeToNBT(update_packet);
    }
    writeInventoryItemToNBT(update_packet,slot);
  }

  protected final void writeInventoryItemToNBT(NBTTagCompound compound,int slot)
  {
    ItemStack is = wineItemStacks[slot];
    NBTTagCompound tag = new NBTTagCompound();
    if(is != null)
    {
      tag.setBoolean("empty", false);
      is.writeToNBT(tag);
    } else
    {
      tag.setBoolean("empty", true);
    }
    compound.setTag("Item_" + String.valueOf(slot), tag);
  }
    
  protected void writeTileToNBT(NBTTagCompound compound)
  {
    super.writeToNBT(compound);
  }

  @Override
  public NBTTagCompound writeToNBT(NBTTagCompound compound)
  {
    if(compound == null)
    {
      compound = new NBTTagCompound();
    }
    int i;
    super.writeToNBT(compound);
    for(i = 0; i < getSizeInventory(); i++)
    {
      writeInventoryItemToNBT(compound,i);
    }
    return compound;
  }
  
    public boolean isUseableByPlayer(EntityPlayer player)
    {
        return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
    }


    public void openInventory(EntityPlayer player)
    {
    }

    public void closeInventory(EntityPlayer player)
    {
    }

public boolean isItemValidForSlot(int index, ItemStack stack) {
	return false;
}

@Override
public int getField(int id) {
	return 0;
}

@Override
public void setField(int id, int value) {		
}

@Override
public int getFieldCount() {
	return 0;
}

    public void clear()
    {
        for (int i = 0; i < this.wineItemStacks.length; ++i)
        {
            this.wineItemStacks[i] = null;
        }
    }

public String getName() {
        return this.hasCustomName() ? this.furnaceCustomName : "Racks";
}

    public boolean hasCustomName()
    {
        return this.furnaceCustomName != null && !this.furnaceCustomName.isEmpty();
    }

@Override
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
        return new ContainerRacks(playerInventory, this);
}

@Override
public String getGuiID() {
	return "10";
}

@Override
public int[] getSlotsForFace(EnumFacing side) {
	return null;
}

@Override
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
        return this.isItemValidForSlot(index, itemStackIn);
}

public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
        return true;
}

@Override 
public void update() {        
}

    public boolean Check0(){  
    	if(wineItemStacks[0] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }
    
    public boolean Check1(){  	
    	if(wineItemStacks[1] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }   

    public boolean Check2(){  	
    	if(wineItemStacks[2] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }  
    
    public boolean Check3(){  	
    	if(wineItemStacks[3] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }  
    
    public boolean Check4(){  	
    	if(wineItemStacks[4] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }  
    
    public boolean Check5(){  	
    	if(wineItemStacks[5] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }  
    
    public boolean Check6(){  	
    	if(wineItemStacks[6] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }  
    
    public boolean Check7(){  	
    	if(wineItemStacks[7] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }  
    
    public boolean Check8(){  	
    	if(wineItemStacks[8] != null)
    	{
    		return true;
    	} else { 
    		return false;
    	}
    }  
    
    @SuppressWarnings("unchecked")
    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing)
    {
        if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
        {
        	return (T) new SidedInvWrapper(this, facing);                    
        }

        return super.getCapability(capability, facing);
    }
    
    @Override
    public final SPacketUpdateTileEntity getUpdatePacket()
    {
      NBTTagCompound nbt = new NBTTagCompound();
      writeToNBT(nbt);    
      return new SPacketUpdateTileEntity(getPos(), 0, nbt);
    }
    
    @Override
    public NBTTagCompound getUpdateTag()
    {
      return writeToNBT(null);
    }
    
    @Override
    public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
    {
      super.onDataPacket(net, pkt);
      if(worldObj.isRemote)
      {
        readFromNBT(pkt.getNbtCompound());
      }
    }
}

 

But I have problem with rotation Wine model.

 

package cz.grossik.farmcraft2.racks;

import org.lwjgl.opengl.GL11;

import cz.grossik.farmcraft2.Main;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderRacks extends TileEntitySpecialRenderer<TileEntityRacks>
{
    private static final ModelWine0 model0 = new ModelWine0();
    private static final ModelWine1 model1 = new ModelWine1();
    private static final ModelWine2 model2 = new ModelWine2();    
    private static final ModelWine3 model3 = new ModelWine3();
    private static final ModelWine4 model4 = new ModelWine4();
    private static final ModelWine5 model5 = new ModelWine5();
    private static final ModelWine6 model6 = new ModelWine6();
    private static final ModelWine7 model7 = new ModelWine7();
    private static final ModelWine8 model8 = new ModelWine8();

    private static final ResourceLocation tWine = new ResourceLocation(Main.MODID + ":textures/wine.png");

    @Override
    public void renderTileEntityAt(TileEntityRacks te, double x, double y, double z, float partialTicks, int destroyStage)
    {
        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, z);
                
        int rotationAngle = 0;
        int metadata = te.getBlockMetadata();
        if (metadata%4 == 0)
        {
   			 rotationAngle = 270;
   	 	}
        if (metadata%4 == 1)
        {
   			 rotationAngle = 90;
   	 	}
        if (metadata%4 == 2)
   	 	{
   			 rotationAngle = 180;
   	 	}
   	 	if (metadata%4 == 3)
   	 	{
   			 rotationAngle = 0;
   	 	}
   	 	
   	 	GL11.glRotatef(rotationAngle, 0, 1, 0);

        ResourceLocation texture0 = tWine;       
        bindTexture(texture0);
        
        GlStateManager.pushMatrix();
        
        if(te.Check0() == true) { model0.render(); }
        
        if(te.Check1() == true) { model1.render(); }
        
        if(te.Check2() == true) { model2.render(); }

        if(te.Check3() == true) { model3.render(); }

        if(te.Check4() == true) { model4.render(); }
        
        if(te.Check5() == true) { model5.render(); }

        if(te.Check6() == true) { model6.render(); }

        if(te.Check7() == true) { model7.render(); }

        if(te.Check8() == true) { model8.render(); }
                
        GlStateManager.popMatrix();
        GlStateManager.popMatrix();
    }
}

 

2mzhXF4.png

Posted

No.  :(

 

jW7gx5r.png

No not specifically GLStateManager.translate(x, y, z), but GLStatemanager.translate(where on the x, where on the y, where on the z). They can be decimals to center it in the block.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.