otter
-
Posts
5 -
Joined
-
Last visited
Posts posted by otter
-
-
Hello,
I've successfully stored the blocks's ID w/in the TileEntity - thanks for that!
I can't figure out how to store the NBT quite yet. Do you have an example?
The breakBlock()-method doesn't seem to interact w/ the player or the ItemStack at all. If I override this, the only benefit would be that I'd be able to prevent removeTileEntity() from being called.
So I tried overriding dropBlockAsItem() - but how on earth do I get the NBT from my TileEntity?
@Override public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) { super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_); //p_149749_1_.removeTileEntity(p_149749_2_, p_149749_3_, p_149749_4_); } @Override protected void dropBlockAsItem(World p_149642_1_, int p_149642_2_, int p_149642_3_, int p_149642_4_, ItemStack p_149642_5_){ TileEntity tile = TileEntityHelper.getTileEntityBaseScannerFromCoords(p_149642_1_, p_149642_2_, p_149642_3_, p_149642_4_); p_149642_5_.setTagCompound()); // super.dropBlockAsItem(p_149642_1_, p_149642_2_, p_149642_3_, p_149642_4_, p_149642_5_); }
-
Hello,
sorry if this is trivial.
I've a block which is supposed to store meta data, in my case information about a different block. I can't figure out how to store "a block w/in a block", though...
My approach:
public class TileEntityBaseScanner extends TileEntity { public Block bb = Blocks.diamond_ore; @Override public void writeToNBT(NBTTagCompound par1) { super.writeToNBT(par1); try { par1.setByteArray("bb", TileEntityHelper.serialize(bb)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void readFromNBT(NBTTagCompound par1) { super.readFromNBT(par1); try { this.bb = (Block) TileEntityHelper.deserialize(par1.getByteArray("bb")); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public class TileEntityHelper { public static byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(out); os.writeObject(obj); return out.toByteArray(); } public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException { ByteArrayInputStream in = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(in); return is.readObject(); } }
Unfortunately, the block class can't be serialized and there's no "NBTTagCompound.setBlock()"-method...
Also, is there any way to store the TileEntity once a block is destroyed? i.e., the player destroys the block and he has the block including the metadata in his inventory?
-
Thank you. This did the job:
int x_mod = x % 16; int x1_border = x; int c = 0; while (x_mod != 0 && c <= 16) { x1_border++; c++; x_mod = (x1_border) % 16; if (debugPlacer) p_149727_1_.setBlock(x1_border, y, z, Blocks.redstone_torch); }
-
Hey,
beginner here, a short question concerning 1.7.2 I couldn't figure out myself by reading the code or Google.
How do I get the current chunk's borders?
This is my current approach:
@Override public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { if(p_149727_1_.isRemote) return false; int x = p_149727_2_; int y = p_149727_3_; int z = p_149727_4_; Chunk currentChunk = p_149727_1_.getChunkFromChunkCoords(x,y); ChunkCoordIntPair CCIP = currentChunk.getChunkCoordIntPair(); int x_border = CCIP.chunkXPos; int z_border = CCIP.chunkZPos; int y_border = currentChunk.heightMap[x_border << 4 | z_border]; // TODO: crash; taken from canBlockSeeTheSky //...
I did some testing and these coordinates definitely aren't the chunks borders but rather the current block's coords. Also, my y_border-method crashes the game via a ArrayIndexOutOfBoundsException (haven't looked into this too much, as soon as I see bit-shifting my mind crashes as well...).
Thanks in advance.
[1.7.2] [Beginner] Store a block w/in a TileEntity / TileEntity in general
in Modder Support
Posted
I've solved it, but it seems awfully complicated for such as basic task.
Here's my solution: