Java Code Examples for net.minecraftforge.common.DimensionManager#isDimensionRegistered()

The following examples show how to use net.minecraftforge.common.DimensionManager#isDimensionRegistered() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PacketRequestTE.java    From LookingGlass with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handle(ByteBuf data, EntityPlayer player) {
	if (ModConfigs.disabled) return;
	int dim = data.readInt();
	int xPos = data.readInt();
	int yPos = data.readInt();
	int zPos = data.readInt();

	if (!DimensionManager.isDimensionRegistered(dim)) return;
	WorldServer world = MinecraftServer.getServer().worldServerForDimension(dim);
	if (world == null) return;
	TileEntity tile = world.getTileEntity(xPos, yPos, zPos);
	if (tile != null) {
		//FIXME: This is currently a very "forceful" method of doing this, and not technically guaranteed to produce correct results
		// This would be much better handled by using the getDescriptionPacket method and wrapping that packet in a LookingGlass
		// packet to control delivery timing, allowing for processing the packet while the correct target world is the active world
		// This idea requires that that system be in place, though, so until then this hack will hopefully hold.
		NBTTagCompound tag = new NBTTagCompound();
		tile.writeToNBT(tag);
		ServerPacketDispatcher.getInstance().addPacket(player, PacketTileEntityNBT.createPacket(xPos, yPos, zPos, tag, dim));
	}
}
 
Example 2
Source File: ProxyWorldManager.java    From LookingGlass with GNU General Public License v3.0 6 votes vote down vote up
public static WorldView createWorldView(int dimid, ChunkCoordinates spawn, int width, int height) {
	if (ModConfigs.disabled) return null;
	if (!DimensionManager.isDimensionRegistered(dimid)) return null;

	WorldClient proxyworld = ProxyWorldManager.getProxyworld(dimid);
	if (proxyworld == null) return null;

	Collection<WorldView> worldviews = worldviewsets.get(dimid);
	if (worldviews == null) return null;

	WorldView view = new WorldView(proxyworld, spawn, width, height);

	// Initialize the view rendering system
	Minecraft mc = Minecraft.getMinecraft();
	EntityLivingBase backup = mc.renderViewEntity;
	mc.renderViewEntity = view.camera;
	view.getRenderGlobal().setWorldAndLoadRenderers(proxyworld);
	mc.renderViewEntity = backup;

	// Inform the server of the new view
	LookingGlassPacketManager.bus.sendToServer(PacketCreateView.createPacket(view));
	worldviews.add(view);
	return view;
}
 
Example 3
Source File: PacketCreateView.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handle(ByteBuf data, EntityPlayer player) {
	if (ModConfigs.disabled) return;
	int dim = data.readInt();
	int xPos = data.readInt();
	int yPos = data.readInt();
	int zPos = data.readInt();
	byte renderDistance = data.readByte();

	if (!DimensionManager.isDimensionRegistered(dim)) return;
	WorldServer world = MinecraftServer.getServer().worldServerForDimension(dim);
	if (world == null) return;
	int x;
	int y;
	int z;
	if (yPos < 0) {
		ChunkCoordinates c = world.getSpawnPoint();
		x = c.posX >> 4;
		y = c.posY >> 4;
		z = c.posZ >> 4;
	} else {
		x = xPos;
		y = yPos;
		z = zPos;
	}
	if (renderDistance > ModConfigs.renderDistance) renderDistance = ModConfigs.renderDistance;
	ChunkFinderManager.instance.addFinder(new ChunkFinder(new ChunkCoordinates(x, y, z), dim, world.getChunkProvider(), player, renderDistance));
	//TODO: Add to tracking list.  Send time/data updates at intervals. Keep in mind to catch player disconnects when tracking clients.
	//Register ChunkFinder, and support change of finder location.
	//TODO: This is a repeat of the handling of PacketRequestWorldInfo
	net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new ClientWorldInfoEvent(dim, (EntityPlayerMP) player));
	LookingGlassPacketManager.bus.sendTo(PacketWorldInfo.createPacket(dim), (EntityPlayerMP) player);
}
 
Example 4
Source File: PacketRequestWorldInfo.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handle(ByteBuf data, EntityPlayer player) {
	if (ModConfigs.disabled) return;
	int dim = data.readInt();

	if (!DimensionManager.isDimensionRegistered(dim)) return;
	net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new ClientWorldInfoEvent(dim, (EntityPlayerMP) player));
	LookingGlassPacketManager.bus.sendTo(PacketWorldInfo.createPacket(dim), (EntityPlayerMP) player);
}
 
Example 5
Source File: PacketRequestChunk.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handle(ByteBuf data, EntityPlayer player) {
	if (ModConfigs.disabled) return;
	int dim = data.readInt();
	int xPos = data.readInt();
	int yPos = data.readInt();
	int zPos = data.readInt();

	if (!DimensionManager.isDimensionRegistered(dim)) return;
	WorldServer world = MinecraftServer.getServer().worldServerForDimension(dim);
	if (world == null) return;
	Chunk chunk = world.getChunkFromChunkCoords(xPos, zPos);
	if (!chunk.isChunkLoaded) chunk = world.getChunkProvider().loadChunk(xPos, zPos);
	ServerPacketDispatcher.getInstance().addPacket(player, PacketChunkInfo.createPacket(chunk, true, yPos, dim));
}
 
Example 6
Source File: ProxyWorldManager.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized WorldClient getProxyworld(int dimid) {
	if (ModConfigs.disabled) return null;
	WorldClient proxyworld = proxyworlds.get(dimid);
	if (proxyworld == null) {
		if (!DimensionManager.isDimensionRegistered(dimid)) return null;
		// We really don't want to be doing this during a render cycle
		if (Minecraft.getMinecraft().thePlayer instanceof EntityCamera) return null; //TODO: This check probably needs to be altered
		WorldClient theWorld = Minecraft.getMinecraft().theWorld;
		if (theWorld != null && theWorld.provider.dimensionId == dimid) proxyworld = theWorld;
		if (proxyworld == null) proxyworld = new ProxyWorld(dimid);
		proxyworlds.put(dimid, proxyworld);
		worldviewsets.put(dimid, Collections.newSetFromMap(new WeakHashMap<WorldView, Boolean>()));
	}
	return proxyworld;
}