Jump to content

Forcing renderer to change texture


DanteZg

Recommended Posts

Im trying to bind a different texture for my render based on variable stored in TileEntity, but the texture doesnt update(even when I place a block next to it, nothing changes). How can I force it to update?

 

Here is my code(some parts are complete mess, especially renderer,  used just for testing).

 

Block

 

public class BlockTable extends BlockContainer{
public BlockTable(int id){
super(id, Material.wood);
this.setCreativeTab(CreativeTabs.tabDecorations);
}

public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
{
this.setBlockBounds(0.1875F, 0F, 0.1875F, 0.8125F, 0.0625F, 0.8125F);
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
this.setBlockBounds(0.375F, 0.0625F, 0.375F, 0.625F, 0.8125F, 0.625F);
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
this.setBlockBounds(0F, 0.875F, 0F, 1F, 1F, 1F);
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 1F);
}


public int idDropped(int par1, Random random, int zero)
{
     return -1;
}

public int damageDropped(int par1)
     {
         return -1;
     }
    
     @SideOnly(Side.CLIENT)
     private Icon[] icons;

     @SideOnly(Side.CLIENT)
     public void registerIcons(IconRegister par1IconRegister)
     {
         icons = new Icon[4];
        
         for(int i = 0; i < icons.length; i++)
         {
             icons[i] = par1IconRegister.registerIcon(WoodworksMain.modid + ":" + (this.getUnlocalizedName().substring(5)));
         }
     }

     @SideOnly(Side.CLIENT)
     public Icon getIcon(int par1, int par2)
     {
         switch(par2)
         {
             case 0:
             return icons[0];
             case 1:
             {
             switch(par1)
                 {
                     case 0:
                         return icons[1];
                     case 1:
                         return icons[2];
                     case 2:
                         return icons[3];
                     default:
                     return icons[0];
                 }
             }
             default:
             {
             System.out.println("Invalid metadata for " + this.getUnlocalizedName());
                 return icons[0];
             }
         }
     }

     @SideOnly(Side.CLIENT)
     public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
     {
         for(int i = 0; i < 4; i++)
         {
                 par3List.add(new ItemStack(par1, 1, i));
         }
     }

@Override
public TileEntity createNewTileEntity(World world) {

return new TileEntityTable();
}

public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
++l;
l %= 4;
TileEntityTable rotation = (TileEntityTable) par1World.getBlockTileEntity(par2, par3, par4);
if (l == 0)
     {
     rotation.setRotation(2); //2
     }
if (l == 1)
     {
     rotation.setRotation(3); //3
     }
if (l == 2)
     {
     rotation.setRotation(0); //0
     }
if (l == 3)
     {
     rotation.setRotation(1); //1
     }
}

public static void dropItemStack(ItemStack item, World world, int x, int y, int z)
{
EntityItem par1EntityItem = new EntityItem(world, x, y, z, item);
par1EntityItem.posX = x;
par1EntityItem.posY = y;
par1EntityItem.posZ = z;
world.spawnEntityInWorld(par1EntityItem);
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
if(!world.isRemote){
TileEntityTable par1tileEntity = (TileEntityTable)world.getBlockTileEntity(x, y, z);
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() == 0)
{
     int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
     par1tileEntity.setState(par1ItemDamage + 1);
     player.inventory.decrStackSize(player.inventory.currentItem, 1);
     player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
     world.markBlockForRenderUpdate(x, y, z);
     return true;
}
}
return true;
}
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
TileEntityTable par1tileEntity = (TileEntityTable)par1World.getBlockTileEntity(par2, par3, par4);
if(par1tileEntity != null){
int par1State = par1tileEntity.getState();
int par1Rotation = par1tileEntity.getRotation();
getBlockHardness(par1World, par2, par3, par4);
if (!par1World.isRemote){
int par1Metadata = par1World.getBlockMetadata(par2, par3, par4);
if(par1State == 0){
     dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.blockTable, 1, par1Metadata), par1World, par2, par3, par4);
}
else if(par1State != 0){
     dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.blockTable, 1, par1Metadata), par1World, par2, par3, par4);
     dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1State-1), par1World, par2, par3, par4);
}
else{
     System.out.println("Something went wrong on breaking Table Block with state: " + par1State + " ,and rotation: " + par1Rotation);
}
}
}
}
public int getRenderType(){
return -1;
}

public boolean isOpaqueCube(){
return false;
}

public boolean renderAsNormalBlock(){
return false;
}
}

 

 

Renderer(complete mess here)

 

import org.lwjgl.opengl.GL11;
import net.woodworks.common.WoodworksCommonProxy;
import net.woodworks.common.WoodworksMain;
import net.woodworks.models.ModelTable;
import net.woodworks.tileentity.TileEntityTable;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
public class RendererTable extends TileEntitySpecialRenderer{

ResourceLocation texture = (new ResourceLocation(""));
ResourceLocation texture_oak_0 = (new ResourceLocation("woodworks", "textures/models/table/table_oak0.png"));
ResourceLocation texture_oak_1 = (new ResourceLocation("woodworks", "textures/models/table/table_oak1.png"));
ResourceLocation texture_oak_2 = (new ResourceLocation("woodworks", "textures/models/table/table_oak2.png"));
ResourceLocation texture_oak_3 = (new ResourceLocation("woodworks", "textures/models/table/table_oak3.png"));
ResourceLocation texture_oak_4 = (new ResourceLocation("woodworks", "textures/models/table/table_oak4.png"));
ResourceLocation texture_oak_5 = (new ResourceLocation("woodworks", "textures/models/table/table_oak5.png"));
ResourceLocation texture_oak_6 = (new ResourceLocation("woodworks", "textures/models/table/table_oak6.png"));
ResourceLocation texture_oak_7 = (new ResourceLocation("woodworks", "textures/models/table/table_oak7.png"));
ResourceLocation texture_oak_8 = (new ResourceLocation("woodworks", "textures/models/table/table_oak8.png"));
ResourceLocation texture_oak_9 = (new ResourceLocation("woodworks", "textures/models/table/table_oak9.png"));
ResourceLocation texture_oak_10 = (new ResourceLocation("woodworks", "textures/models/table/table_oak10.png"));
ResourceLocation texture_oak_11 = (new ResourceLocation("woodworks", "textures/models/table/table_oak11.png"));
ResourceLocation texture_oak_12 = (new ResourceLocation("woodworks", "textures/models/table/table_oak12.png"));
ResourceLocation texture_oak_13 = (new ResourceLocation("woodworks", "textures/models/table/table_oak13.png"));
ResourceLocation texture_oak_14 = (new ResourceLocation("woodworks", "textures/models/table/table_oak14.png"));
ResourceLocation texture_oak_15 = (new ResourceLocation("woodworks", "textures/models/table/table_oak15.png"));
ResourceLocation texture_oak_16 = (new ResourceLocation("woodworks", "textures/models/table/table_oak16.png"));

ResourceLocation texture_spruce_0 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce0.png"));
ResourceLocation texture_spruce_1 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce1.png"));
ResourceLocation texture_spruce_2 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce2.png"));
ResourceLocation texture_spruce_3 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce3.png"));
ResourceLocation texture_spruce_4 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce4.png"));
ResourceLocation texture_spruce_5 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce5.png"));
ResourceLocation texture_spruce_6 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce6.png"));
ResourceLocation texture_spruce_7 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce7.png"));
ResourceLocation texture_spruce_8 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce8.png"));
ResourceLocation texture_spruce_9 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce9.png"));
ResourceLocation texture_spruce_10 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce10.png"));
ResourceLocation texture_spruce_11 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce11.png"));
ResourceLocation texture_spruce_12 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce12.png"));
ResourceLocation texture_spruce_13 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce13.png"));
ResourceLocation texture_spruce_14 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce14.png"));
ResourceLocation texture_spruce_15 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce15.png"));
ResourceLocation texture_spruce_16 = (new ResourceLocation("woodworks", "textures/models/table/table_spruce16.png"));

ResourceLocation texture_birch_0 = (new ResourceLocation("woodworks", "textures/models/table/table_birch0.png"));
ResourceLocation texture_birch_1 = (new ResourceLocation("woodworks", "textures/models/table/table_birch1.png"));
ResourceLocation texture_birch_2 = (new ResourceLocation("woodworks", "textures/models/table/table_birch2.png"));
ResourceLocation texture_birch_3 = (new ResourceLocation("woodworks", "textures/models/table/table_birch3.png"));
ResourceLocation texture_birch_4 = (new ResourceLocation("woodworks", "textures/models/table/table_birch4.png"));
ResourceLocation texture_birch_5 = (new ResourceLocation("woodworks", "textures/models/table/table_birch5.png"));
ResourceLocation texture_birch_6 = (new ResourceLocation("woodworks", "textures/models/table/table_birch6.png"));
ResourceLocation texture_birch_7 = (new ResourceLocation("woodworks", "textures/models/table/table_birch7.png"));
ResourceLocation texture_birch_8 = (new ResourceLocation("woodworks", "textures/models/table/table_birch8.png"));
ResourceLocation texture_birch_9 = (new ResourceLocation("woodworks", "textures/models/table/table_birch9.png"));
ResourceLocation texture_birch_10 = (new ResourceLocation("woodworks", "textures/models/table/table_birch10.png"));
ResourceLocation texture_birch_11 = (new ResourceLocation("woodworks", "textures/models/table/table_birch11.png"));
ResourceLocation texture_birch_12 = (new ResourceLocation("woodworks", "textures/models/table/table_birch12.png"));
ResourceLocation texture_birch_13 = (new ResourceLocation("woodworks", "textures/models/table/table_birch13.png"));
ResourceLocation texture_birch_14 = (new ResourceLocation("woodworks", "textures/models/table/table_birch14.png"));
ResourceLocation texture_birch_15 = (new ResourceLocation("woodworks", "textures/models/table/table_birch15.png"));
ResourceLocation texture_birch_16 = (new ResourceLocation("woodworks", "textures/models/table/table_birch16.png"));

ResourceLocation texture_jungle_0 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle0.png"));
ResourceLocation texture_jungle_1 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle1.png"));
ResourceLocation texture_jungle_2 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle2.png"));
ResourceLocation texture_jungle_3 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle3.png"));
ResourceLocation texture_jungle_4 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle4.png"));
ResourceLocation texture_jungle_5 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle5.png"));
ResourceLocation texture_jungle_6 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle6.png"));
ResourceLocation texture_jungle_7 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle7.png"));
ResourceLocation texture_jungle_8 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle8.png"));
ResourceLocation texture_jungle_9 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle9.png"));
ResourceLocation texture_jungle_10 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle10.png"));
ResourceLocation texture_jungle_11 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle11.png"));
ResourceLocation texture_jungle_12 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle12.png"));
ResourceLocation texture_jungle_13 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle13.png"));
ResourceLocation texture_jungle_14 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle14.png"));
ResourceLocation texture_jungle_15 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle15.png"));
ResourceLocation texture_jungle_16 = (new ResourceLocation("woodworks", "textures/models/table/table_jungle16.png"));


Object blockTable = WoodworksCommonProxy.blockTable;

private ModelTable modelTable;

public RendererTable(){
this.modelTable = new ModelTable();
}


@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
GL11.glPushMatrix();
int rotationAngle = 0;
switch(((TileEntityTable) tileentity).getRotation()){
case 0:
rotationAngle = 270;
break;
case 1:
rotationAngle = 0;
break;
case 2:
rotationAngle = 90;
break;
case 3:
rotationAngle = 180;
break;
}
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z +0.5F);
GL11.glRotatef(rotationAngle, 0F, 1F, 0F);
GL11.glRotatef(180, 0F, 0F, 1F);
if(tileentity.getBlockMetadata() == 0){
switch(((TileEntityTable) tileentity).getState()){
case 0:
     this.bindTexture(texture_oak_0);
     break;
case 1:
     this.bindTexture(texture_oak_1);
     break;
case 2:
     this.bindTexture(texture_oak_2);
     break;
case 3:
     this.bindTexture(texture_oak_3);
     break;
case 4:
     this.bindTexture(texture_oak_4);
     break;
case 5:
     this.bindTexture(texture_oak_5);
     break;
case 6:
     this.bindTexture(texture_oak_6);
     break;
case 7:
     this.bindTexture(texture_oak_7);
     break;
case 8:
     this.bindTexture(texture_oak_;
     break;
case 9:
     this.bindTexture(texture_oak_9);
     break;
case 10:
     this.bindTexture(texture_oak_10);
     break;
case 11:
     this.bindTexture(texture_oak_11);
     break;
case 12:
     this.bindTexture(texture_oak_12);
     break;
case 13:
     this.bindTexture(texture_oak_13);
     break;
case 14:
     this.bindTexture(texture_oak_14);
     break;
case 15:
     this.bindTexture(texture_oak_15);
     break;
case 16:
     this.bindTexture(texture_oak_16);
     break;
}}
else if(tileentity.getBlockMetadata() == 1){
switch(((TileEntityTable) tileentity).getState()){
case 0:
     this.bindTexture(texture_spruce_0);
     break;
case 1:
     this.bindTexture(texture_spruce_1);
     break;
case 2:
     this.bindTexture(texture_spruce_2);
     break;
case 3:
     this.bindTexture(texture_spruce_3);
     break;
case 4:
     this.bindTexture(texture_spruce_4);
     break;
case 5:
     this.bindTexture(texture_spruce_5);
     break;
case 6:
     this.bindTexture(texture_spruce_6);
     break;
case 7:
     this.bindTexture(texture_spruce_7);
     break;
case 8:
     this.bindTexture(texture_spruce_;
     break;
case 9:
     this.bindTexture(texture_spruce_9);
     break;
case 10:
     this.bindTexture(texture_spruce_10);
     break;
case 11:
     this.bindTexture(texture_spruce_11);
     break;
case 12:
     this.bindTexture(texture_spruce_12);
     break;
case 13:
     this.bindTexture(texture_spruce_13);
     break;
case 14:
     this.bindTexture(texture_spruce_14);
     break;
case 15:
     this.bindTexture(texture_spruce_15);
     break;
case 16:
     this.bindTexture(texture_spruce_16);
     break;
}}
else if(tileentity.getBlockMetadata() == 2){
switch(((TileEntityTable) tileentity).getState()){
case 0:
     this.bindTexture(texture_birch_0);
     break;
case 1:
     this.bindTexture(texture_birch_1);
     break;
case 2:
     this.bindTexture(texture_birch_2);
     break;
case 3:
     this.bindTexture(texture_birch_3);
     break;
case 4:
     this.bindTexture(texture_birch_4);
     break;
case 5:
     this.bindTexture(texture_birch_5);
     break;
case 6:
     this.bindTexture(texture_birch_6);
     break;
case 7:
     this.bindTexture(texture_birch_7);
     break;
case 8:
     this.bindTexture(texture_birch_;
     break;
case 9:
     this.bindTexture(texture_birch_9);
     break;
case 10:
     this.bindTexture(texture_birch_10);
     break;
case 11:
     this.bindTexture(texture_birch_11);
     break;
case 12:
     this.bindTexture(texture_birch_12);
     break;
case 13:
     this.bindTexture(texture_birch_13);
     break;
case 14:
     this.bindTexture(texture_birch_14);
     break;
case 15:
     this.bindTexture(texture_birch_15);
     break;
case 16:
     this.bindTexture(texture_birch_16);
     break;
}}
else if(tileentity.getBlockMetadata() == 2){
switch(((TileEntityTable) tileentity).getState()){
case 0:
     this.bindTexture(texture_jungle_0);
     break;
case 1:
     this.bindTexture(texture_jungle_1);
     break;
case 2:
     this.bindTexture(texture_jungle_2);
     break;
case 3:
     this.bindTexture(texture_jungle_3);
     break;
case 4:
     this.bindTexture(texture_jungle_4);
     break;
case 5:
     this.bindTexture(texture_jungle_5);
     break;
case 6:
     this.bindTexture(texture_jungle_6);
     break;
case 7:
     this.bindTexture(texture_jungle_7);
     break;
case 8:
     this.bindTexture(texture_jungle_;
     break;
case 9:
     this.bindTexture(texture_jungle_9);
     break;
case 10:
     this.bindTexture(texture_jungle_10);
     break;
case 11:
     this.bindTexture(texture_jungle_11);
     break;
case 12:
     this.bindTexture(texture_jungle_12);
     break;
case 13:
     this.bindTexture(texture_jungle_13);
     break;
case 14:
     this.bindTexture(texture_jungle_14);
     break;
case 15:
     this.bindTexture(texture_jungle_15);
     break;
case 16:
     this.bindTexture(texture_jungle_16);
     break;
}}
GL11.glPushMatrix();
modelTable.renderModel(0.0625F);
GL11.glPopMatrix();
GL11.glPopMatrix();
}

}

 

 

Every code I try doesnt seem to work. :/

Link to comment
Share on other sites

package net.woodworks.tileentity;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityTable extends TileEntity {

private int cloth;
private int rotation;

@Override
public void writeToNBT(NBTTagCompound compound)
{
	super.writeToNBT(compound);
	compound.setInteger("cloth", cloth);
	compound.setInteger("rotation", rotation);
}

@Override
public void readFromNBT(NBTTagCompound compound)
{
	super.readFromNBT(compound);
	cloth=compound.getInteger("cloth");
	rotation=compound.getInteger("rotation");
}



//Getter
public int getState()
{
	return cloth;
}

public int getRotation()
{
	return rotation;
}
//Setter
public void setState(int par1)
{
	cloth = par1;
	System.out.println("Setting state integer:" + par1);
}

public void setRotation(int par1)
{
	rotation = par1;
	System.out.println("Setting rotation integer:" + par1);
}
}

Link to comment
Share on other sites

The cool thing is that vanilla handles 99% of it for you, just add this:

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

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

The cool thing is that vanilla handles 99% of it for you, just add this:

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

Thank you! However I never made a mod where I would have to sync packets. So I really dont know how this is done. Where should I put this?

Link to comment
Share on other sites

The cool thing is that vanilla handles 99% of it for you, just add this:

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

Thank you! However I never made a mod where I would have to sync packets. So I really dont know how this is done. Where should I put this?

 

Inside your tile entity class.  That's ALL you need to do in this case.

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

The cool thing is that vanilla handles 99% of it for you, just add this:

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

Thank you! However I never made a mod where I would have to sync packets. So I really dont know how this is done. Where should I put this?

 

Inside your tile entity class.  That's ALL you need to do in this case.

 

Thats what I tought, however the still texture doesnt update/change. Even when I manually force a block to update.

Link to comment
Share on other sites

Is the value that controls your texture saved to NBT?

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

Is the value that controls your texture saved to NBT?

 

Yes, Its saved, everything else works, except that the textures stay the same. I havent finished all the textures, so when I run the game I get an error missing texture bla bla, it isnt possible that this could be causing this error? Aslo, you have my code above if you are interested in helping me out. Thank you btw.

Link to comment
Share on other sites

Yes, Its saved, everything else works, except that the textures stay the same. I havent finished all the textures, so when I run the game I get an error missing texture bla bla, it isnt possible that this could be causing this error? Aslo, you have my code above if you are interested in helping me out. Thank you btw.

 

If you're changing from one missing texture to another...

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

OK I have noticed that when I'm in singleplayer and after I quit and then rejoin the textures get updated. When I'm testing the server I get this error:

 

---- Minecraft Crash Report ----
// I just don't know what went wrong 

Time: 1/16/14 9:30 PM
Description: Ticking memory connection

java.lang.NullPointerException
at net.woodworks.blocks.BlockTable.onBlockActivated(BlockTable.java:166)
at net.minecraft.item.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:421)
at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:556)
at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)

 

Yes, Its saved, everything else works, except that the textures stay the same. I havent finished all the textures, so when I run the game I get an error missing texture bla bla, it isnt possible that this could be causing this error? Aslo, you have my code above if you are interested in helping me out. Thank you btw.

 

If you're changing from one missing texture to another...

 

I'm not :)

Link to comment
Share on other sites

Okay I have figured out what have I done wrong and I have fixed that NullPointException, now the same thing happens on the server, when I setState to integer, the texture doesnt change until I log out and log in again. Please help me, this is the last thing holding me from releasing my mod.

Link to comment
Share on other sites

Mmm~

Client-server disparity.

Solved by packets.

 

You're sure you have this in your TE?

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

And that right after you change the value you call world.notifyBlockChange()?

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

Mmm~

Client-server disparity.

Solved by packets.

 

You're sure you have this in your TE?

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

And that right after you change the value you call world.notifyBlockChange()?

 

I have fixed that error with packets. Yeah here is my code:

	@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
	if(!world.isRemote){
		TileEntityTable par1tileEntity = (TileEntityTable)world.getBlockTileEntity(x, y, z);
			if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() == 0)
			{
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				par1tileEntity.setState(par1ItemDamage + 1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
			else if(player.getCurrentEquippedItem().getItem() != net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() != 0){
				int par1ItemDamage = par1tileEntity.getState();
				dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1ItemDamage-1), world, x, y, z);
				par1tileEntity.setState(0);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
			else if(player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() != 0){
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				int par1State = par1tileEntity.getState();
				if(par1ItemDamage != par1State-1){
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1State-1), world, x, y, z);
				par1tileEntity.setState(par1ItemDamage + 1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
				}
			}
			else if(par1tileEntity.getState() == 1 && player.getCurrentEquippedItem().getItem() == Item.dyePowder){
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				par1tileEntity.setState(par1ItemDamage +1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
	}
	return true;

}	

 

However the textures only change after you rejoin the world.

 

EDIT: I threw a bunch of this rerender methods(check to new code) and now it rerenders after clicking right click 2 times with the same item. Any ideas now? :D

 

	public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
	if(!world.isRemote){
		TileEntityTable par1tileEntity = (TileEntityTable)world.getBlockTileEntity(x, y, z);
			if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() == 0)
			{
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				par1tileEntity.setState(par1ItemDamage + 1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.markBlockForRenderUpdate(x, y, z);
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
			else if(player.getCurrentEquippedItem().getItem() != net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() != 0){
				int par1ItemDamage = par1tileEntity.getState();
				dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1ItemDamage-1), world, x, y, z);
				par1tileEntity.setState(0);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.markBlockForRenderUpdate(x, y, z);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
			else if(player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() != 0){
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				int par1State = par1tileEntity.getState();
				if(par1ItemDamage != par1State-1){
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1State-1), world, x, y, z);
				par1tileEntity.setState(par1ItemDamage + 1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.markBlockForRenderUpdate(x, y, z);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
				}
			}
			else if(par1tileEntity.getState() == 1 && player.getCurrentEquippedItem().getItem() == Item.dyePowder){
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				par1tileEntity.setState(par1ItemDamage +1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.markBlockForRenderUpdate(x, y, z);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
	}
	world.markBlockForUpdate(x,y,z);
	world.notifyBlockChange(x, y, z, this.blockID);
	player.worldObj.markBlockForRenderUpdate(x, y, z);
	Minecraft.getMinecraft().renderGlobal.markBlockForRenderUpdate(x, y, z);
	return true;

}	

 

EDIT2: Got it to work! I will post my final code later tonight (I need to rewrite some things) so everyone with this problem can use it! Thank you for your help Draco!

 

EDIT3: Server crashes now!

 

EDIT4: Code works but it needs some serious rewriting, I'll be back in a few.

Link to comment
Share on other sites

That code does not help solve the problem as there are NO references to packets in that function.

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.