Java Code Examples for net.minecraft.world.chunk.Chunk#isEmpty()

The following examples show how to use net.minecraft.world.chunk.Chunk#isEmpty() . 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: SchematicWorldRenderingNotifier.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void updateBetweenY(int minY, int maxY)
{
    World world = SchematicWorldHandler.getSchematicWorld();

    if (world != null)
    {
        RenderGlobal rg = LitematicaRenderer.getInstance().getWorldRenderer();
        Long2ObjectMap<Chunk> schematicChunks = ((IMixinChunkProviderClient) (Object) world.getChunkProvider()).getLoadedChunks();
        Long2ObjectMap<Chunk> clientChunks = ((IMixinChunkProviderClient) (Object) Minecraft.getMinecraft().world.getChunkProvider()).getLoadedChunks();

        for (Chunk chunk : schematicChunks.values())
        {
            // Only mark chunks that are actually rendered (if the schematic world contains more chunks)
            if (chunk.isEmpty() == false && clientChunks.containsKey(ChunkPos.asLong(chunk.x, chunk.z)))
            {
                rg.markBlockRangeForRenderUpdate((chunk.x << 4) - 1, minY, (chunk.z << 4) - 1, (chunk.x << 4) + 16, maxY, (chunk.z << 4) + 16);
            }
        }
    }
}
 
Example 2
Source File: MixinChunk.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@Inject(method = "addEntity(Lnet/minecraft/entity/Entity;)V", at = @At("HEAD"), cancellable = true)
public void preAddEntity(Entity entityIn, CallbackInfo callbackInfo) {
    World world = this.world;

    int i = MathHelper.floor(entityIn.posX / 16.0D);
    int j = MathHelper.floor(entityIn.posZ / 16.0D);

    if (i == this.x && j == this.z) {
        // do nothing, and let vanilla code take over after our injected code is done
        // (now)
    } else {
        Chunk realChunkFor = world.getChunk(i, j);
        if (!realChunkFor.isEmpty() && realChunkFor.loaded) {
            realChunkFor.addEntity(entityIn);
            callbackInfo.cancel(); // don't run the code on this chunk!!!
        }
    }
}
 
Example 3
Source File: ChunkManager.java    From mapwriter with MIT License 6 votes vote down vote up
public void updateUndergroundChunks() {
	int chunkArrayX = (this.mw.playerXInt >> 4) - 1;
	int chunkArrayZ = (this.mw.playerZInt >> 4) - 1;
	MwChunk[] chunkArray = new MwChunk[9];
	for (int z = 0; z < 3; z++) {
		for (int x = 0; x < 3; x++) {
			Chunk chunk = this.mw.mc.theWorld.getChunkFromChunkCoords(
				chunkArrayX + x,
				chunkArrayZ + z
			);
			if (!chunk.isEmpty()) {
				chunkArray[(z * 3) + x] = copyToMwChunk(chunk);
			}
		}
	}
}
 
Example 4
Source File: SchematicWorldRenderingNotifier.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void updateBetweenX(int minX, int maxX)
{
    World world = SchematicWorldHandler.getSchematicWorld();

    if (world != null)
    {
        final int xMin = Math.min(minX, maxX);
        final int xMax = Math.max(minX, maxX);
        final int cxMin = (xMin >> 4);
        final int cxMax = (xMax >> 4);
        RenderGlobal rg = LitematicaRenderer.getInstance().getWorldRenderer();
        Long2ObjectMap<Chunk> schematicChunks = ((IMixinChunkProviderClient) (Object) world.getChunkProvider()).getLoadedChunks();
        Long2ObjectMap<Chunk> clientChunks = ((IMixinChunkProviderClient) (Object) Minecraft.getMinecraft().world.getChunkProvider()).getLoadedChunks();

        for (Chunk chunk : schematicChunks.values())
        {
            // Only mark chunks that are actually rendered (if the schematic world contains more chunks)
            if (chunk.x >= cxMin && chunk.x <= cxMax && chunk.isEmpty() == false &&
                clientChunks.containsKey(ChunkPos.asLong(chunk.x, chunk.z)))
            {
                minX = Math.max( chunk.x << 4      , xMin);
                maxX = Math.min((chunk.x << 4) + 15, xMax);
                rg.markBlockRangeForRenderUpdate(minX, 0, (chunk.z << 4), maxX, 255, (chunk.z << 4) + 15);
            }
        }
    }
}
 
Example 5
Source File: SchematicWorldRenderingNotifier.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void updateBetweenZ(int minZ, int maxZ)
{
    World world = SchematicWorldHandler.getSchematicWorld();

    if (world != null)
    {
        final int zMin = Math.min(minZ, maxZ);
        final int zMax = Math.max(minZ, maxZ);
        final int czMin = (zMin >> 4);
        final int czMax = (zMax >> 4);
        RenderGlobal rg = LitematicaRenderer.getInstance().getWorldRenderer();
        Long2ObjectMap<Chunk> schematicChunks = ((IMixinChunkProviderClient) (Object) world.getChunkProvider()).getLoadedChunks();
        Long2ObjectMap<Chunk> clientChunks = ((IMixinChunkProviderClient) (Object) Minecraft.getMinecraft().world.getChunkProvider()).getLoadedChunks();

        for (Chunk chunk : schematicChunks.values())
        {
            // Only mark chunks that are actually rendered (if the schematic world contains more chunks)
            if (chunk.z >= czMin && chunk.z <= czMax && chunk.isEmpty() == false &&
                clientChunks.containsKey(ChunkPos.asLong(chunk.x, chunk.z)))
            {
                minZ = Math.max( chunk.z << 4      , zMin);
                maxZ = Math.min((chunk.z << 4) + 15, zMax);
                rg.markBlockRangeForRenderUpdate((chunk.x << 4), 0, minZ, (chunk.x << 4) + 15, 255, maxZ);
            }
        }
    }
}
 
Example 6
Source File: ClientStateMachine.java    From malmo with MIT License 5 votes vote down vote up
private boolean isChunkReady()
{
    // First, find the starting position we ought to have:
    List<AgentSection> agents = currentMissionInit().getMission().getAgentSection();
    if (agents == null || agents.size() <= currentMissionInit().getClientRole())
        return true;    // This should never happen.
    AgentSection as = agents.get(currentMissionInit().getClientRole());
    if (as.getAgentStart() != null && as.getAgentStart().getPlacement() != null)
    {
        PosAndDirection pos = as.getAgentStart().getPlacement();
        int x = MathHelper.floor(pos.getX().doubleValue()) >> 4;
        int z = MathHelper.floor(pos.getZ().doubleValue()) >> 4;
        // Now get the chunk we should be starting in:
        IChunkProvider chunkprov = Minecraft.getMinecraft().world.getChunkProvider();
        EntityPlayerSP player = Minecraft.getMinecraft().player;
        if (player.addedToChunk)
        {
            // Our player is already added to a chunk - is it the right one?
            Chunk actualChunk = chunkprov.provideChunk(player.chunkCoordX, player.chunkCoordZ);
            Chunk requestedChunk = chunkprov.provideChunk(x,  z);
            if (actualChunk == requestedChunk && actualChunk != null && !actualChunk.isEmpty())
            {
                // We're in the right chunk, and it's not an empty chunk.
                // We're ready to proceed, but first set our client positions to where we ought to be.
                // The server should be doing this too, but there's no harm (probably) in doing it ourselves.
                player.posX = pos.getX().doubleValue();
                player.posY = pos.getY().doubleValue();
                player.posZ = pos.getZ().doubleValue();
                return true;
            }
        }
        return false;   // Our starting position has been specified, but it's not yet ready.
    }
    return true;    // No starting position specified, so doesn't matter where we start.
}
 
Example 7
Source File: ChunkFinder.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isBlockNormalCubeDefault(Chunk chunk, int par1, int par2, int par3, boolean par4) {
	if (par1 >= -30000000 && par3 >= -30000000 && par1 < 30000000 && par3 < 30000000) {
		if (chunk != null && !chunk.isEmpty()) {
			Block block = chunk.getBlock(par1 & 15, par2, par3 & 15);
			return block.isNormalCube();
		}
	}
	return par4;
}
 
Example 8
Source File: PacketChunkInfo.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public void handle(EntityPlayer player, byte[] chunkData, int dim, int xPos, int zPos, boolean reqinit, short yPos, short yMSBPos) {
	WorldClient proxyworld = ProxyWorldManager.getProxyworld(dim);
	if (proxyworld == null) return;
	if (proxyworld.provider.dimensionId != dim) return;

	//TODO: Test to see if this first part is even necessary
	Chunk chunk = proxyworld.getChunkProvider().provideChunk(xPos, zPos);
	if (reqinit && (chunk == null || chunk.isEmpty())) {
		if (yPos == 0) {
			proxyworld.doPreChunk(xPos, zPos, false);
			return;
		}
		proxyworld.doPreChunk(xPos, zPos, true);
	}
	// End possible removal section
	proxyworld.invalidateBlockReceiveRegion(xPos << 4, 0, zPos << 4, (xPos << 4) + 15, 256, (zPos << 4) + 15);
	chunk = proxyworld.getChunkFromChunkCoords(xPos, zPos);
	if (reqinit && (chunk == null || chunk.isEmpty())) {
		proxyworld.doPreChunk(xPos, zPos, true);
		chunk = proxyworld.getChunkFromChunkCoords(xPos, zPos);
	}
	if (chunk != null) {
		chunk.fillChunk(chunkData, yPos, yMSBPos, reqinit);
		receivedChunk(proxyworld, xPos, zPos);
		if (!reqinit || !(proxyworld.provider instanceof WorldProviderSurface)) {
			chunk.resetRelightChecks();
		}
	}
}
 
Example 9
Source File: PacketChunkInfo.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public void receivedChunk(WorldClient worldObj, int cx, int cz) {
	worldObj.markBlockRangeForRenderUpdate(cx << 4, 0, cz << 4, (cx << 4) + 15, 256, (cz << 4) + 15);
	Chunk c = worldObj.getChunkFromChunkCoords(cx, cz);
	if (c == null || c.isEmpty()) return;

	for (WorldView activeview : ProxyWorldManager.getWorldViews(worldObj.provider.dimensionId)) {
		activeview.onChunkReceived(cx, cz);
	}

	int x = (cx << 4);
	int z = (cz << 4);
	for (int y = 0; y < worldObj.getActualHeight(); y += 16) {
		if (c.getAreLevelsEmpty(y, y)) continue;
		for (int x2 = 0; x2 < 16; ++x2) {
			for (int z2 = 0; z2 < 16; ++z2) {
				for (int y2 = 0; y2 < 16; ++y2) {
					int lx = x + x2;
					int ly = y + y2;
					int lz = z + z2;
					if (worldObj.getBlock(lx, ly, lz).hasTileEntity(worldObj.getBlockMetadata(lx, ly, lz))) {
						LookingGlassPacketManager.bus.sendToServer(PacketRequestTE.createPacket(lx, ly, lz, worldObj.provider.dimensionId));
					}
				}
			}
		}
	}
}
 
Example 10
Source File: ChunkManager.java    From mapwriter with MIT License 5 votes vote down vote up
private void addSaveChunkTask(Chunk chunk) {
	if ((this.mw.multiplayer && this.mw.regionFileOutputEnabledMP) || 
		(!this.mw.multiplayer && this.mw.regionFileOutputEnabledSP)) {
		if (!chunk.isEmpty()) {
			this.mw.executor.addTask(new SaveChunkTask(copyToMwChunk(chunk), this.mw.regionManager));
		}
	}
}
 
Example 11
Source File: ClientChunkSize.java    From ForgeHax with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onTick(ClientTickEvent event) {
  if (getWorld() == null || getLocalPlayer() == null || running) {
    return;
  }
  
  switch (event.phase) {
    case END: {
      Chunk chunk = getWorld().getChunkFromBlockCoords(getLocalPlayer().getPosition());
      if (chunk.isEmpty()) {
        return;
      }
      
      ChunkPos pos = chunk.getPos();
      if (!pos.equals(current) || (timer.isStarted() && timer.hasTimeElapsed(1000L))) {
        // chunk changed, don't show diff between different chunks
        if (current != null && !pos.equals(current)) {
          size = previousSize = 0L;
        }
        
        current = pos;
        running = true;
        
        // process size calculation on another thread
        Executors.defaultThreadFactory()
            .newThread(
                () -> {
                  try {
                    final NBTTagCompound root = new NBTTagCompound();
                    NBTTagCompound level = new NBTTagCompound();
                    root.setTag("Level", level);
                    root.setInteger("DataVersion", 1337);
                    
                    try {
                      // this should be done on the main mc thread but it works 99% of the
                      // time outside it
                      AnvilChunkLoader loader = new AnvilChunkLoader(DUMMY, null);
                      Methods.AnvilChunkLoader_writeChunkToNBT.invoke(
                          loader, chunk, getWorld(), level);
                    } catch (Throwable t) {
                      size = -1L;
                      previousSize = 0L;
                      return; // couldn't save chunk
                    }
                    
                    DataOutputStream compressed =
                        new DataOutputStream(
                            new BufferedOutputStream(
                                new DeflaterOutputStream(new ByteArrayOutputStream(8096))));
                    try {
                      CompressedStreamTools.write(root, compressed);
                      previousSize = size;
                      size = compressed.size();
                    } catch (IOException e) {
                      size = -1L;
                      previousSize = 0L;
                    }
                  } finally {
                    timer.start();
                    running = false;
                  }
                })
            .start();
      }
      break;
    }
    default:
      break;
  }
}