Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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).

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

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?

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.

  • Author

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;
}

}

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

How did you place your StupidSpawner? Please show the code related with placing the block.

It seems that there would be the problem.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.