Jump to content

[1.8]Portals that transports both entities AND players?


NovaViper

Recommended Posts

Hey, is it in anyway possible to make a custom portal that transports both entities and players? I started but it causes the non-player entity to be teleported to and from the dimensions rapidly, causing lots of lag and it ends up spawning multiple 'clones' of the same entity.

 

My code is up to date and posted on Github: https://github.com/NovaViper/ZeroQuest/tree/master/src/main/java/common/zeroquest/block/portal

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

if (player.timeUntilPortal > 0) {
     player.timeUntilPortal = 10;
}

 

This code looks suspicous. If I'm understanding it correctly you're resetting the timeUntilPortal field when it's more than zero. Also, I don't know for sure, but onEntityCollidedWithBlock might be called every tick the player is touching the block.

Link to comment
Share on other sites

I did that already

 

	private void travelToDimension(Entity entity, int id) {
	if (!entity.worldObj.isRemote && !entity.isDead) {
		entity.worldObj.theProfiler.startSection("changeDimension");
		MinecraftServer minecraftserver = MinecraftServer.getServer();
		int j = entity.dimension;
		WorldServer worldserver = minecraftserver.worldServerForDimension(j);
		WorldServer worldserver1 = minecraftserver.worldServerForDimension(id);
		entity.dimension = id;

		if (j == 1 && id == 1) {
			worldserver1 = minecraftserver.worldServerForDimension(0);
			entity.dimension = 0;
		}

		entity.worldObj.removeEntity(entity);
		entity.isDead = false;
		entity.worldObj.theProfiler.startSection("reposition");
		entity.timeUntilPortal = 10;
		minecraftserver.getConfigurationManager().transferEntityToWorld(entity, j, worldserver, worldserver1, new TeleporterNillax(worldserver1));
		entity.worldObj.theProfiler.endStartSection("reloading");
		Entity entity1 = EntityList.createEntityByName(EntityList.getEntityString(entity), worldserver1);

		if (entity1 != null) {
			entity1.copyDataFromOld(entity);

			if (j == 1 && id == 1) {
				BlockPos spawnPoint = worldserver1.getSpawnPoint();
				spawnPoint = entity.worldObj.getTopSolidOrLiquidBlock(spawnPoint);
				entity1.setLocationAndAngles(spawnPoint.getX(), spawnPoint.getY(), spawnPoint.getZ(), entity1.rotationYaw, entity1.rotationPitch);
			}

			worldserver1.spawnEntityInWorld(entity1);
		}

		entity.isDead = true;
		entity.worldObj.theProfiler.endSection();
		worldserver.resetUpdateEntityTick();
		worldserver1.resetUpdateEntityTick();
		entity.worldObj.theProfiler.endSection();
	}
}

 

The entity teleports but it rapidly teleports, which causes the cloning and lag

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

I took it out because it caused even more lag than before I added it in

 

	private void travelToDimension(Entity entity, int id) {
	if (!entity.worldObj.isRemote && !entity.isDead) {
		entity.worldObj.theProfiler.startSection("changeDimension");
		MinecraftServer minecraftserver = MinecraftServer.getServer();
		int j = entity.dimension;
		WorldServer worldserver = minecraftserver.worldServerForDimension(j);
		WorldServer worldserver1 = minecraftserver.worldServerForDimension(id);
		entity.dimension = id;

		if (j == 1 && id == 1) {
			worldserver1 = minecraftserver.worldServerForDimension(0);
			entity.dimension = 0;
		}

		entity.timeUntilPortal = 10;
		entity.worldObj.removeEntity(entity);
		entity.isDead = false;
		entity.worldObj.theProfiler.startSection("reposition");
		entity.timeUntilPortal = 10;
		minecraftserver.getConfigurationManager().transferEntityToWorld(entity, j, worldserver, worldserver1, new TeleporterNillax(worldserver1));
		entity.worldObj.theProfiler.endStartSection("reloading");
		Entity entity1 = EntityList.createEntityByName(EntityList.getEntityString(entity), worldserver1);

		if (entity1 != null) {
			entity1.copyDataFromOld(entity);

			if (j == 1 && id == 1) {
				BlockPos spawnPoint = worldserver1.getSpawnPoint();
				spawnPoint = entity.worldObj.getTopSolidOrLiquidBlock(spawnPoint);
				entity1.setLocationAndAngles(spawnPoint.getX(), spawnPoint.getY(), spawnPoint.getZ(), entity1.rotationYaw, entity1.rotationPitch);
			}

			worldserver1.spawnEntityInWorld(entity1);
			entity.timeUntilPortal = 10;
		}

		entity.isDead = true;
		entity.worldObj.theProfiler.endSection();
		worldserver.resetUpdateEntityTick();
		worldserver1.resetUpdateEntityTick();
		entity.worldObj.theProfiler.endSection();
	}
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

So.. I should put the cooldown where it acutally transfers the entity to the dimension, like this?

 

	private void travelToDimension(Entity entity, int id) {
	if (!entity.worldObj.isRemote && !entity.isDead) {
		entity.worldObj.theProfiler.startSection("changeDimension");
		MinecraftServer minecraftserver = MinecraftServer.getServer();
		int j = entity.dimension;
		WorldServer worldserver = minecraftserver.worldServerForDimension(j);
		WorldServer worldserver1 = minecraftserver.worldServerForDimension(id);
		entity.dimension = id;

		if (j == 1 && id == 1) {
			worldserver1 = minecraftserver.worldServerForDimension(0);
			entity.dimension = 0;
		}

		entity.worldObj.removeEntity(entity);
		entity.isDead = false;
		entity.worldObj.theProfiler.startSection("reposition");
		minecraftserver.getConfigurationManager().transferEntityToWorld(entity, j, worldserver, worldserver1, new TeleporterNillax(worldserver1));
		entity.timeUntilPortal = 10;
		entity.worldObj.theProfiler.endStartSection("reloading");
		Entity entity1 = EntityList.createEntityByName(EntityList.getEntityString(entity), worldserver1);

		if (entity1 != null) {
			entity1.copyDataFromOld(entity);

			if (j == 1 && id == 1) {
				BlockPos spawnPoint = worldserver1.getSpawnPoint();
				spawnPoint = entity.worldObj.getTopSolidOrLiquidBlock(spawnPoint);
				entity1.setLocationAndAngles(spawnPoint.getX(), spawnPoint.getY(), spawnPoint.getZ(), entity1.rotationYaw, entity1.rotationPitch);
			}

			worldserver1.spawnEntityInWorld(entity1);
		}

		entity.isDead = true;
		entity.worldObj.theProfiler.endSection();
		worldserver.resetUpdateEntityTick();
		worldserver1.resetUpdateEntityTick();
		entity.worldObj.theProfiler.endSection();
	}
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

It works for a little bit but then it begins to lag out, which leaves the entity stuck in the portal and cloning only in the Nillax Dimension

 

	private void travelToDimension(Entity entity, int id) {
	if (!entity.worldObj.isRemote && !entity.isDead) {
		entity.timeUntilPortal = 10;

		entity.worldObj.theProfiler.startSection("changeDimension");
		MinecraftServer minecraftserver = MinecraftServer.getServer();
		int j = entity.dimension;
		WorldServer worldserver = minecraftserver.worldServerForDimension(j);
		WorldServer worldserver1 = minecraftserver.worldServerForDimension(id);
		entity.dimension = id;

		if (j == 1 && id == 1) {
			worldserver1 = minecraftserver.worldServerForDimension(0);
			entity.dimension = 0;
		}

		entity.worldObj.removeEntity(entity);
		entity.isDead = false;
		entity.worldObj.theProfiler.startSection("reposition");
		minecraftserver.getConfigurationManager().transferEntityToWorld(entity, j, worldserver, worldserver1, new TeleporterNillax(worldserver1));
		entity.worldObj.theProfiler.endStartSection("reloading");
		Entity entity1 = EntityList.createEntityByName(EntityList.getEntityString(entity), worldserver1);

		if (entity1 != null) {
			entity1.copyDataFromOld(entity);

			if (j == 1 && id == 1) {
				BlockPos spawnPoint = worldserver1.getSpawnPoint();
				spawnPoint = entity.worldObj.getTopSolidOrLiquidBlock(spawnPoint);
				entity1.setLocationAndAngles(spawnPoint.getX(), spawnPoint.getY(), spawnPoint.getZ(), entity1.rotationYaw, entity1.rotationPitch);
			}

			worldserver1.spawnEntityInWorld(entity1);
		}

		entity.isDead = true;
		entity.worldObj.theProfiler.endSection();
		worldserver.resetUpdateEntityTick();
		worldserver1.resetUpdateEntityTick();
		entity.worldObj.theProfiler.endSection();
	}
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

So, use getPortalCooldown() at the end of the method?

 

	private void travelToDimension(Entity entity, int id) {
	if (!entity.worldObj.isRemote && !entity.isDead) {
		entity.timeUntilPortal = 10;

		entity.worldObj.theProfiler.startSection("changeDimension");
		MinecraftServer minecraftserver = MinecraftServer.getServer();
		int j = entity.dimension;
		WorldServer worldserver = minecraftserver.worldServerForDimension(j);
		WorldServer worldserver1 = minecraftserver.worldServerForDimension(id);
		entity.dimension = id;

		if (j == 1 && id == 1) {
			worldserver1 = minecraftserver.worldServerForDimension(0);
			entity.dimension = 0;
		}

		entity.worldObj.removeEntity(entity);
		entity.isDead = false;
		entity.worldObj.theProfiler.startSection("reposition");
		minecraftserver.getConfigurationManager().transferEntityToWorld(entity, j, worldserver, worldserver1, new TeleporterNillax(worldserver1));
		entity.worldObj.theProfiler.endStartSection("reloading");
		Entity entity1 = EntityList.createEntityByName(EntityList.getEntityString(entity), worldserver1);

		if (entity1 != null) {
			entity1.copyDataFromOld(entity);

			if (j == 1 && id == 1) {
				BlockPos spawnPoint = worldserver1.getSpawnPoint();
				spawnPoint = entity.worldObj.getTopSolidOrLiquidBlock(spawnPoint);
				entity1.setLocationAndAngles(spawnPoint.getX(), spawnPoint.getY(), spawnPoint.getZ(), entity1.rotationYaw, entity1.rotationPitch);
			}

			worldserver1.spawnEntityInWorld(entity1);
		}

		entity.isDead = true;
		entity.worldObj.theProfiler.endSection();
		worldserver.resetUpdateEntityTick();
		worldserver1.resetUpdateEntityTick();
		entity.worldObj.theProfiler.endSection();
		entity.getPortalCooldown();
	}
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

I'm now confused now

......

You should set Entity#timeUntilPortal to Entity#getPortalCooldown() when an entity is teleported,

and only teleport the entity when the counter is smaller than 0.

Then make the counter of the colliding entity decrease.

 

Please learn how to construct logic..

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

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

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

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