Hello everybody. This is AbrarSyed, maker of the SecretRoomsMod
I recently added a new feature, a camouflage block. Currently it its a one wya Block that has one side that adapts to its environment, all the other sides are see-through glass. I have it working for Single Player perfectly, but I can't seem to make it work for SMP.
What ive been doing/ the blocks behavior
1) onBlockPlaced
---- Get facing direction and save in Metadata
---- create tile entity
---- Get Texture from surroundings
---- ---- use getBlockTexture(world, i+1, j, k, l); where ijk is coordinates and l is the facing.
---- save texture IconIndex in tile entity
2) when block is rendered
---- get TileEntity using iBlockAccess.getBlockEntity(i,j ,k) where iBlockAccess is an instance of World, and ijk are coordinates
---- return texture from TileEntity on designated side from Metdata.
as I said, works fine in SSP. But when I try to do this on the Server with ModLoaderMP I get a small problem. The adapted texture is only displayed to the player that placed it. To all other players the camouflage side always shows texture 0 for some reason. Any ideas to fix this?
In SMP, any Entity (which includes TileEntities) will not transmit state unless the game is aware it needs to. Any new type of entity you add, like yours, is not included in that list. You'll need to mess with custom packets to make the other clients aware of what texture it picked - this thread has more information in the first couple posts.
In SMP, any Entity (which includes TileEntities) will not transmit state unless the game is aware it needs to. Any new type of entity you add, like yours, is not included in that list. You'll need to mess with custom packets to make the other clients aware of what texture it picked - this thread has more information in the first couple posts.
yeah, I used that to port it in the first place, but it referred to mobs and entities like arrows. I wasn't sure if the same applied to TileEntities. Thanks, Ill check that out. :biggrin.gif: +1
yeah, I used that to port it in the first place, but it referred to mobs and entities like arrows. I wasn't sure if the same applied to TileEntities. Thanks, Ill check that out. :biggrin.gif: +1
Huh, I looked and TileEntity actually isn't a subclass of Entity. I can be wrong about some things apparently! They still won't transmit random state though, only things the game already knows about. At least that's how it's worked in my experience.
Huh, I looked and TileEntity actually isn't a subclass of Entity. I can be wrong about some things apparently! They still won't transmit random state though, only things the game already knows about. At least that's how it's worked in my experience.
hmmm. Well what you said sent me in the right direction. I found a method in ModLoaderMP...
I'd appreciate you posting if that worked or not; I've never seen that method before and I'd like to know if that solves this problem for my own reference :smile.gif:
It could also be perhaps that the the Block only updates itself on rendering. And since the Server doesn't render, It wouldn't have the texture. Somehow I need to send and handle packets for this... but I don't know how.
Off the top of my head, how I'd do it something like this:
Make a custom Item that places your block. When you rightclick and place it in that Item's rightclick handler, do your texture searching on the client. Once you find the texture you want, use a Packet230 to send it to the server (along with the xyz of the block). When the server gets this packet, it creates the tileentity and saves that iconindex, and then fires back another Packet230 to all clients with that same information so they construct the tileentity with the correct icon index. Or set the index if it already exists. I'm actually not entirely sure how that part would work, I'm not 100% familiar with how TileEntities are handled on the client (or if they're a server-only thing).
The problem with this is that if the block whose texture it's imitating changes you won't have a client around to tell you what the new texture is. You'd have to warn your users to destroy and re-place the block, I guess.
Off the top of my head, how I'd do it something like this:
Make a custom Item that places your block. When you rightclick and place it in that Item's rightclick handler, do your texture searching on the client. Once you find the texture you want, use a Packet230 to send it to the server (along with the xyz of the block). When the server gets this packet, it creates the tileentity and saves that iconindex, and then fires back another Packet230 to all clients with that same information so they construct the tileentity with the correct icon index. Or set the index if it already exists. I'm actually not entirely sure how that part would work, I'm not 100% familiar with how TileEntities are handled on the client (or if they're a server-only thing).
The problem with this is that if the block whose texture it's imitating changes you won't have a client around to tell you what the new texture is. You'd have to warn your users to destroy and re-place the block, I guess.
Good luck!
Then I save it in the TileNtity. Eveyr time it renders, it checks the TileEntity.
what I have it currently doing is that it detects what the block is and stuff in the OnPlacedByPlayer method.
and right now, I decided that the block is not gonna change after it has been placed. Even if blocks are added arround it, it won't conform to them. It will stay as it is.
From what I can tell by looking at the code, minecraft should handle updates to metadata and tile entities automatically. It's not though and I can't figure out why. Really starting to aggravate me. It only seems to work for vanilla block IDs but I can't find the code that says which blocks work and which dont. For example in Railcraft I reimplement normal rails with my own class under the same id as BlockRail used, and they seem to send metadata updates as do the Boosters. But none of my rails or blocks with new IDs do.
I know I can send a custom packet with the information, but I hate to do that without knowing why I have to. There is a lot of performance code to prevent packet spamming involved. =/
Correction: It seems at least metadata is being synced on some of my new rails, but not the blocks.
EDIT: Hours later it turns out the problem was a renamed function in the item class that was placing the blocks with no metadata on the server. getPlacedMetadata -> getMetadata
I recently added a new feature, a camouflage block. Currently it its a one wya Block that has one side that adapts to its environment, all the other sides are see-through glass. I have it working for Single Player perfectly, but I can't seem to make it work for SMP.
What ive been doing/ the blocks behavior
1) onBlockPlaced
---- Get facing direction and save in Metadata
---- create tile entity
---- Get Texture from surroundings
---- ---- use getBlockTexture(world, i+1, j, k, l); where ijk is coordinates and l is the facing.
---- save texture IconIndex in tile entity
2) when block is rendered
---- get TileEntity using iBlockAccess.getBlockEntity(i,j ,k) where iBlockAccess is an instance of World, and ijk are coordinates
---- return texture from TileEntity on designated side from Metdata.
as I said, works fine in SSP. But when I try to do this on the Server with ModLoaderMP I get a small problem. The adapted texture is only displayed to the player that placed it. To all other players the camouflage side always shows texture 0 for some reason. Any ideas to fix this?
INFORMATION WANTS TO BE WRONG
yeah, I used that to port it in the first place, but it referred to mobs and entities like arrows. I wasn't sure if the same applied to TileEntities. Thanks, Ill check that out. :biggrin.gif: +1
Huh, I looked and TileEntity actually isn't a subclass of Entity. I can be wrong about some things apparently! They still won't transmit random state though, only things the game already knows about. At least that's how it's worked in my experience.
INFORMATION WANTS TO BE WRONG
hmmm. Well what you said sent me in the right direction. I found a method in ModLoaderMP...
im prettu sure that this is what I was looking for. Thanks :biggrin.gif:
INFORMATION WANTS TO BE WRONG
Make a custom Item that places your block. When you rightclick and place it in that Item's rightclick handler, do your texture searching on the client. Once you find the texture you want, use a Packet230 to send it to the server (along with the xyz of the block). When the server gets this packet, it creates the tileentity and saves that iconindex, and then fires back another Packet230 to all clients with that same information so they construct the tileentity with the correct icon index. Or set the index if it already exists. I'm actually not entirely sure how that part would work, I'm not 100% familiar with how TileEntities are handled on the client (or if they're a server-only thing).
The problem with this is that if the block whose texture it's imitating changes you won't have a client around to tell you what the new texture is. You'd have to warn your users to destroy and re-place the block, I guess.
Good luck!
INFORMATION WANTS TO BE WRONG
Then I save it in the TileNtity. Eveyr time it renders, it checks the TileEntity.
what I have it currently doing is that it detects what the block is and stuff in the OnPlacedByPlayer method.
and right now, I decided that the block is not gonna change after it has been placed. Even if blocks are added arround it, it won't conform to them. It will stay as it is.
Hmm. Ill try your advice... perhaps it will work.
I know I can send a custom packet with the information, but I hate to do that without knowing why I have to. There is a lot of performance code to prevent packet spamming involved. =/
Correction: It seems at least metadata is being synced on some of my new rails, but not the blocks.
EDIT: Hours later it turns out the problem was a renamed function in the item class that was placing the blocks with no metadata on the server. getPlacedMetadata -> getMetadata