Jump to content

[1.4.7] Bug with Textures


Moritz

Recommended Posts

Hello.

 

I did find out how to make the facing (thanks to cpws Iron chest and Ic2)

 

But now I have the problem that the blocks does have all the same facing (when i place an other block all other Blocks faces to his side too)

 

How can i fix this bug?

 

Source Here:

 

Block:

 

file 239 lines (190 sloc) 5.642 kb EditRawBlameHistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package speiger.src.tinychest.common.blocks;

import java.util.List;
import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import speiger.src.api.common.addonslib.tinychest.TinyChestIDs;
import speiger.src.tinychest.TinyChest;
import speiger.src.tinychest.common.tileentity.TileEntityBasicTinyChest;
import speiger.src.tinychest.common.tileentity.basic.*;


import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockTinyChest extends BlockContainer
{
private static TinyChestIDs tiny;
public BlockTinyChest(int id)
{
	super(id, Material.iron);
	this.setCreativeTab(TinyChest.tinyChest);


}




    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3)
    {
        par3.add(new ItemStack(par1, 1, 0));
        par3.add(new ItemStack(par1, 1, 1));
        par3.add(new ItemStack(par1, 1, 2));
        par3.add(new ItemStack(par1, 1, 3));
        par3.add(new ItemStack(par1, 1, 4));
        par3.add(new ItemStack(par1, 1, 5));
        par3.add(new ItemStack(par1, 1, 6));
        par3.add(new ItemStack(par1, 1, 7));
        par3.add(new ItemStack(par1, 1, );
    }

    public int quantityDropped(Random par1Random)
    {
        return 1;
    }
    
    public int damageDropped(int par1)
    {
        return par1;
    }
    
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return this.blockID;
    }
    
    

    
    
    public boolean onBlockActivated(World par1, int par2, int par3, int par4, EntityPlayer par5, int par6, float par7, float par8, float par9)
    {
    	
    	
    	
    	
    	
    	if(par5.isSneaking())
    	{
    		return false;
    	}
    	
    	if(!par1.isRemote)
    	{
    		int id = 0;
    		int meta = par1.getBlockMetadata(par2, par3, par4);
    		if(meta == 0)
    		{
    			id = tiny.tinychestguieins;
    		}
    		else if(meta == 1)
    		{
    			id = tiny.tinychestguizwei;
    		}
    		else if(meta == 2)
    		{
    			id = tiny.tinychestguidrei;
    		}    		
    		else if(meta == 3)
    		{
    			id = tiny.tinychestguivier;
    		}
    		else if(meta == 4)
    		{
    			id = tiny.tinychestguifunf;
    		}
    		else if(meta == 5)
    		{
    			id = tiny.tinychestguisechs;
    		}
    		else if(meta == 6)
    		{
    			id = tiny.tinychestguisieben;
    		}
    		else if(meta == 7)
    		{
    			id = tiny.tinychestguiacht;
    		}
    		else if(meta == 
    		{
    			id = tiny.tinychestguineun;
    		}

    		TileEntityBasicTinyChest tile = (TileEntityBasicTinyChest)par1.getBlockTileEntity(par2, par3, par4);
    		if(tile != null)
    		{
    			par5.openGui(TinyChest.instance, id, par1, par2, par3, par4);
    			return true;
    		}
    		
    	}
	return true;
    	
    }
    
    @Override
    public boolean isOpaqueCube()
    {
        return false;
    }
    

@Override
public TileEntity createNewTileEntity(World var1) 
{
	return null;
}

@Override
public TileEntity createNewTileEntity(World var1, int meta) 
{

	if(meta == 0) return new BasicTinyChestEins();
	else if(meta == 1) return new BasicTinyChestZwei();
	else if(meta == 2) return new BasicTinyChestDrei();
	else if(meta == 3) return new BasicTinyChestVier();
	else if(meta == 4) return new BasicTinyChestFunf();
	else if(meta == 5) return new BasicTinyChestSechs();
	else if(meta == 6) return new BasicTinyChestSieben();
	else if(meta == 7) return new BasicTinyChestAcht();
	else if(meta ==  return new BasicTinyChestNeun();


	return null;
}

@SideOnly(Side.CLIENT)
@Override
public int getBlockTexture(IBlockAccess var1, int var2, int var3, int var4, int side)
{
	int meta = var1.getBlockMetadata(var2, var3, var4);
	TileEntityBasicTinyChest tile = (TileEntityBasicTinyChest)var1.getBlockTileEntity(var2, var3, var4);

	if(side == tile.getFacing())
	{
		if(meta == 0) return 1;
		else if(meta == 1) return 2;
		else if(meta == 2) return 3;
		else if(meta == 3) return 4;
		else if(meta == 4) return 5;
		else if(meta == 5) return 6;
		else if(meta == 6) return 7;
		else if(meta == 7) return 8;
		else if(meta ==  return 9;
		else return 0;
	}
	else if(side == 0 || side == 1)
	{
		return 0;
	}
	else
	{
		return 10;
	}		
}

@Override
    public void onBlockPlacedBy(World var1, int var2, int var3, int var4, EntityLiving var5)
    {
    	
        if (!var1.isRemote)
        {
            TileEntityBasicTinyChest var6 = (TileEntityBasicTinyChest)var1.getBlockTileEntity(var2, var3, var4);

            if (var5 == null)
            {
            	var6.setFacing(2);
            }
            else
            {
                int var7 = MathHelper.floor_double((double)(var5.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
                switch (var7)
                {
                    case 0:
                    	var6.setFacing(2);
                        break;

                    case 1:
                    	var6.setFacing(5);
                    	break;

                    case 2:
                    	var6.setFacing(3);
                    	break;

                    case 3:
                    	var6.setFacing(4);
                }
            }               
        }
    
    }



}

 

 

TileEntity:

file 178 lines (137 sloc) 4.01 kb EditRawBlameHistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package speiger.src.tinychest.common.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public abstract class TileEntityBasicTinyChest extends TileEntity implements IInventory
{

private String InventoryName;
private ItemStack[] TinyInventory;
private static int face = 0;

public TileEntityBasicTinyChest()
{
}

public TileEntityBasicTinyChest(String par1, int par2)
{
	InventoryName = par1;
	TinyInventory = new ItemStack[par2];
}

    public int getSizeInventory()
    {
        return this.TinyInventory.length;
    }


    public ItemStack getStackInSlot(int par1)
    {
        return this.TinyInventory[par1];
    }


    public ItemStack decrStackSize(int par1, int par2)
    {
        if (this.TinyInventory[par1] != null)
        {
            ItemStack var3;

            if (this.TinyInventory[par1].stackSize <= par2)
            {
                var3 = this.TinyInventory[par1];
                this.TinyInventory[par1] = null;
                return var3;
            }
            else
            {
                var3 = this.TinyInventory[par1].splitStack(par2);

                if (this.TinyInventory[par1].stackSize == 0)
                {
                    this.TinyInventory[par1] = null;
                }

                return var3;
            }
        }
        else
        {
            return null;
        }
    }

    
    public ItemStack getStackInSlotOnClosing(int par1)
    {
        if (this.TinyInventory[par1] != null)
        {
            ItemStack var2 = this.TinyInventory[par1];
            this.TinyInventory[par1] = null;
            return var2;
        }
        else
        {
            return null;
        }
    }

    
    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    {
        this.TinyInventory[par1] = par2ItemStack;

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

    
    public String getInvName()
    {
        return InventoryName;
    }

public int getInventoryStackLimit() {
	return 64;
}


public boolean isUseableByPlayer(EntityPlayer var1) 
{
	return true;
}


public void openChest() 
{
}


    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        NBTTagList var2 = par1NBTTagCompound.getTagList("Items");
        this.TinyInventory = new ItemStack[this.getSizeInventory()];

        for (int var3 = 0; var3 < var2.tagCount(); ++var3)
        {
            NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
            byte var5 = var4.getByte("Slot");

            if (var5 >= 0 && var5 < this.TinyInventory.length)
            {
                this.TinyInventory[var5] = ItemStack.loadItemStackFromNBT(var4);
            }
        }
        
        face = par1NBTTagCompound.getInteger("face");
    }

    /**
     * Writes a tile entity to NBT.
     */
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setInteger("face", face);
        NBTTagList var2 = new NBTTagList();

        for (int var3 = 0; var3 < this.TinyInventory.length; ++var3)
        {
            if (this.TinyInventory[var3] != null)
            {
                NBTTagCompound var4 = new NBTTagCompound();
                var4.setByte("Slot", (byte)var3);
                this.TinyInventory[var3].writeToNBT(var4);
                var2.appendTag(var4);
            }
        }

        par1NBTTagCompound.setTag("Items", var2);
        
    }

public void closeChest() 
{
}

public void setFacing(int i)
{
	face = i;
}


public int getFacing()
{
	return face;
}


}

Link to comment
Share on other sites

Link to comment
Share on other sites

Problem!!!!!!!!!!

 

I have no Clue about Packethandlers! I never worked with them. I need a very good tutorial which explain everything not like this:

You have to do this and this and this.

For me its to much planed tutorial. (Step 1 do this Step 2 do that. Now you are finish. But what did i do there?)

Link to comment
Share on other sites

I have no clue about Packet Handlers datas and everything.

 

With this i would make a try and error and i would fail with this.

And there is no good tutorial with packetdata. (I mean with explaining).

I have problems with implement something which i do not understand!

Link to comment
Share on other sites

I did write Packet Handler ore Packet datas! And i know that you write that i do not need this.

 

I do not understand anything with packet datas. I have to read the source of it (bzw (german word) the classes)

I tell you what i do not understand when i read them!

Link to comment
Share on other sites

I never worked with packetdata/handler!

I do not know how to use it right!

Thats my problem. I read the source of IronChest2 to understand it. But no luck.

 

So how can i use the packets thing that this bug does no longer stay. (Because i want to make a block that use the facing!)

 

Link to comment
Share on other sites

Do you mean i have to implement this code?

I copied out of Mekanismen.

	@Override
public void setFacing(short direction) 
{
	if(canSetFacing(direction))
	{
		facing = direction;
	}

	PacketHandler.sendTileEntityPacketToClients(this, 0, getNetworkedData(new ArrayList()));
}

@Override
public void handlePacketData(ByteArrayDataInput dataStream)
{
	facing = dataStream.readInt();
	worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
	worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
}

@Override
public ArrayList getNetworkedData(ArrayList data)
{
	data.add(facing);
	return data;
}


Link to comment
Share on other sites

No need for a packet handler at all.

Override 2 methods in your TileEntity (eclipse has a handy tool for this: Source menu->Override/Implement methods): onDataPacket and getDescriptionPacket

In getDescriptionPacket create a new NBTTagCompound. Store all the data you need on the client into that NBT (if the customParam from the Packet [see below] is enough, just make this null). Then return a new Packet132TileEntityData. The constructor parameters are x, y, z (there are fields for that in the TileEntity), customParam (can be a number between -128 and +127, you can use this for your facing), yourNBTTagCompound (may be null if you don't need one).

 

In onDataPacket you get the packet back, so just read the data you wrote into it back from it.

 

ok i implemented the two functions in the class now the rest i do not understand? what do you mean with  this:

 

In getDescriptionPacket create a new NBTTagCompound. Store all the data you need on the client into that NBT 

 

and what do you mean with that?

(if the customParam from the Packet [see below] is enough, just make this null). Then return a new Packet132TileEntityData. The constructor parameters are x, y, z (there are fields for that in the TileEntity), customParam (can be a number between -128 and +127, you can use this for your facing), yourNBTTagCompound (may be null if you don't need one).

 

 

 

Link to comment
Share on other sites

hmmm i think i know what you mean. I need time for testing. If i understood you right i know what i have to do.

Sry but my language is limited and sometimes i need a push into the right way and then it needs time to understand (and reading sources)

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.