ForgePatch/src/main/java/net/minecraftforge/client/MinecraftForgeClient.java

96 lines
2.6 KiB
Java
Raw Normal View History

2011-07-15 23:13:09 +00:00
/**
* This software is provided under the terms of the Minecraft Forge Public
2011-07-15 23:13:09 +00:00
* License v1.0.
*/
package net.minecraftforge.client;
import java.util.BitSet;
import java.util.concurrent.TimeUnit;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkCache;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
public class MinecraftForgeClient
{
public static int getRenderPass()
{
return ForgeHooksClient.renderPass;
}
public static BlockRenderLayer getRenderLayer()
{
return ForgeHooksClient.renderLayer.get();
}
private static BitSet stencilBits = new BitSet(8);
static
{
stencilBits.set(0,8);
}
/**
* Reserve a stencil bit for use in rendering
*
* Note: you must check the Framebuffer you are working with to
* determine if stencil bits are enabled on it before use.
*
* @return A bit or -1 if no further stencil bits are available
*/
public static int reserveStencilBit()
{
int bit = stencilBits.nextSetBit(0);
if (bit >= 0)
{
stencilBits.clear(bit);
}
return bit;
}
/**
* Release the stencil bit for other use
*
* @param bit The bit from {@link #reserveStencilBit()}
*/
public static void releaseStencilBit(int bit)
{
if (bit >= 0 && bit < stencilBits.length())
{
stencilBits.set(bit);
}
}
private static final LoadingCache<Pair<World, BlockPos>, ChunkCache> regionCache = CacheBuilder.newBuilder()
.maximumSize(500)
.concurrencyLevel(5)
.expireAfterAccess(1, TimeUnit.SECONDS)
.build(new CacheLoader<Pair<World, BlockPos>, ChunkCache>()
{
public ChunkCache load(Pair<World, BlockPos> key) throws Exception
{
return new ChunkCache(key.getLeft(), key.getRight().add(-1, -1, -1), key.getRight().add(16, 16, 16), 1);
}
});
public static void onRebuildChunk(World world, BlockPos position, ChunkCache cache)
{
regionCache.put(Pair.of(world, position), cache);
}
public static ChunkCache getRegionRenderCache(World world, BlockPos pos)
{
int x = pos.getX() & ~0xF;
int y = pos.getY() & ~0xF;
int z = pos.getZ() & ~0xF;
return regionCache.getUnchecked(Pair.of(world, new BlockPos(x, y, z)));
}
}