Eternaldoom Posted February 6, 2015 Posted February 6, 2015 Hi, I've created a basic mob spawner TileEntity, but I'm having a problem where the worldObj is sometimes always remote. It works fine when the block is placed, but not when it generates in the provideChunk() method in my ChunkProvider. Here's my code: public class TileEntityStupidSpawner extends TileEntity { private String entityName; private int spawnTimer; private Random rand = new Random(); @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); this.entityName = tag.getString("EntityName"); } @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); tag.setString("EntityName", this.entityName); } @Override public void updateEntity() { super.updateEntity(); for(int n = 0; n < 3; n++) { DivineRPG.proxy.spawnParticle(this.worldObj, this.xCoord+0.5, this.yCoord+0.5, this.zCoord+0.5, "blackFlame", true, 3); } if(!this.worldObj.isRemote && this.worldObj.getClosestPlayer(this.xCoord+0.5D, this.yCoord+0.5D, this.zCoord+0.5D, 16D) != null) { if(this.spawnTimer > 0) this.spawnTimer--; if(this.spawnTimer == 0) { int c = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord, this.zCoord, this.xCoord+1, this.yCoord+1, this.zCoord+1).expand(8, 6, ).size(); if (c < { for(int i = 0; i < 4; i++) { Entity e = EntityList.createEntityByName(this.entityName, this.worldObj); if (e != null) { int x = this.xCoord + this.rand.nextInt(9) - 4; int y = this.yCoord + this.rand.nextInt(3) - 1; int z = this.zCoord + this.rand.nextInt(9) - 4; AxisAlignedBB boundingBox = AxisAlignedBB.getBoundingBox(x+e.boundingBox.minX, y+e.boundingBox.minY, z+e.boundingBox.minZ, x+e.boundingBox.maxX, y+e.boundingBox.maxY, z+e.boundingBox.maxZ); if (this.worldObj.checkNoEntityCollision(boundingBox) && this.worldObj.getCollidingBoundingBoxes(e, boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(boundingBox)) { e.setLocationAndAngles(x, y, z, this.rand.nextInt(360), 0); this.worldObj.spawnEntityInWorld(e); } } } } this.spawnTimer = 400; } } } public void setEntityName(String name) { this.entityName = name; } } Putting print statements in updateEntity shows that sometimes it works as expected, with the worldObj being remote half the time and not the other half, but sometimes it is constantly remote. Even when it isn't, mobs are never spawned. If I make it spawn mobs on the client, they appear normally (but don't move of course). Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
SanAndreaP Posted February 6, 2015 Posted February 6, 2015 So it works when it is placed by other means, but it only doesn't work if used in provideChunk within your own ChunkProvider? Can we see your ChunkProvider then? Quote Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
Eternaldoom Posted February 6, 2015 Author Posted February 6, 2015 Here's the ChunkProvider: http://pastebin.com/6wahCzv3 The ArcanaChunk class just has methods to set blocks. Here it is: public class ArcanaChunk { private Block[] data; private byte[] meta; public ArcanaChunk() { data = new Block[32768]; meta = new byte[32768]; } public void setBlock(int x, int y, int z, Block b) { this.setBlock(x, y, z, b, 0); } public void setBlock(int x, int y, int z, Block b, int m) { data[x<<11 | z<<7 | y] = b; meta[x<<11 | z<<7 | y] = (byte)m; } public Block getBlock(int x, int y, int z) { return data[x<<11 | z<<7 | y]; } public Block[] getChunkData() { return data; } public byte[] getChunkMetadata() { return meta; } } Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
Abastro Posted February 7, 2015 Posted February 7, 2015 How did you place your StupidSpawner? Please show the code related with placing the block. It seems that there would be the problem. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
Recommended Posts
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.