2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2019-02-10 22:57:03 +00:00
|
|
|
* Copyright (c) 2016-2019.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2012-08-06 22:07:53 +00:00
|
|
|
package net.minecraftforge.client;
|
2011-07-15 23:04:10 +00:00
|
|
|
|
2019-01-11 23:22:32 +00:00
|
|
|
import java.io.IOException;
|
2013-05-16 00:29:47 +00:00
|
|
|
import java.util.BitSet;
|
2019-01-11 23:22:32 +00:00
|
|
|
import java.util.HashMap;
|
2016-12-17 21:27:45 +00:00
|
|
|
import java.util.Locale;
|
2016-01-01 15:15:48 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2019-01-11 23:22:32 +00:00
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
2016-01-01 15:15:48 +00:00
|
|
|
|
2016-12-17 21:27:45 +00:00
|
|
|
import net.minecraft.client.Minecraft;
|
2019-01-11 23:22:32 +00:00
|
|
|
import net.minecraft.client.renderer.texture.NativeImage;
|
|
|
|
import net.minecraft.resources.IResource;
|
|
|
|
import net.minecraft.resources.IResourceManager;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
2019-01-11 23:22:32 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-05-18 10:29:10 +00:00
|
|
|
import net.minecraft.world.ChunkCache;
|
2016-01-01 15:15:48 +00:00
|
|
|
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;
|
2011-07-15 23:04:10 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
public class MinecraftForgeClient
|
|
|
|
{
|
2013-03-07 03:26:29 +00:00
|
|
|
public static int getRenderPass()
|
2013-03-07 03:18:26 +00:00
|
|
|
{
|
|
|
|
return ForgeHooksClient.renderPass;
|
|
|
|
}
|
2013-05-09 00:13:19 +00:00
|
|
|
|
2016-03-01 12:58:03 +00:00
|
|
|
public static BlockRenderLayer getRenderLayer()
|
2014-12-26 05:39:12 +00:00
|
|
|
{
|
2015-02-08 23:46:01 +00:00
|
|
|
return ForgeHooksClient.renderLayer.get();
|
2014-12-26 05:39:12 +00:00
|
|
|
}
|
|
|
|
|
2016-12-17 21:27:45 +00:00
|
|
|
/**
|
|
|
|
* returns the Locale set by the player in Minecraft.
|
|
|
|
* Useful for creating string and number formatters.
|
|
|
|
*/
|
|
|
|
public static Locale getLocale()
|
|
|
|
{
|
2018-09-22 10:40:22 +00:00
|
|
|
return Minecraft.getInstance().getLanguageManager().getCurrentLanguage().getJavaLocale();
|
2016-12-17 21:27:45 +00:00
|
|
|
}
|
|
|
|
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
private static BitSet stencilBits = new BitSet(8);
|
2013-05-16 00:29:47 +00:00
|
|
|
static
|
|
|
|
{
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
stencilBits.set(0,8);
|
2013-05-16 00:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reserve a stencil bit for use in rendering
|
|
|
|
*
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
* Note: you must check the Framebuffer you are working with to
|
|
|
|
* determine if stencil bits are enabled on it before use.
|
|
|
|
*
|
2013-05-16 00:29:47 +00:00
|
|
|
* @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)
|
|
|
|
{
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
if (bit >= 0 && bit < stencilBits.length())
|
2013-05-16 00:29:47 +00:00
|
|
|
{
|
|
|
|
stencilBits.set(bit);
|
|
|
|
}
|
|
|
|
}
|
2016-01-01 15:15:48 +00:00
|
|
|
|
2016-05-18 10:29:10 +00:00
|
|
|
private static final LoadingCache<Pair<World, BlockPos>, ChunkCache> regionCache = CacheBuilder.newBuilder()
|
2016-01-01 15:15:48 +00:00
|
|
|
.maximumSize(500)
|
|
|
|
.concurrencyLevel(5)
|
|
|
|
.expireAfterAccess(1, TimeUnit.SECONDS)
|
2016-05-18 10:29:10 +00:00
|
|
|
.build(new CacheLoader<Pair<World, BlockPos>, ChunkCache>()
|
2016-01-01 15:15:48 +00:00
|
|
|
{
|
2017-06-18 01:24:17 +00:00
|
|
|
@Override
|
2018-04-22 21:40:38 +00:00
|
|
|
public ChunkCache load(Pair<World, BlockPos> key)
|
2016-01-01 15:15:48 +00:00
|
|
|
{
|
2016-05-18 10:29:10 +00:00
|
|
|
return new ChunkCache(key.getLeft(), key.getRight().add(-1, -1, -1), key.getRight().add(16, 16, 16), 1);
|
2016-01-01 15:15:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-18 10:29:10 +00:00
|
|
|
public static void onRebuildChunk(World world, BlockPos position, ChunkCache cache)
|
2016-01-01 15:15:48 +00:00
|
|
|
{
|
|
|
|
regionCache.put(Pair.of(world, position), cache);
|
|
|
|
}
|
|
|
|
|
2016-05-18 10:29:10 +00:00
|
|
|
public static ChunkCache getRegionRenderCache(World world, BlockPos pos)
|
2016-01-01 15:15:48 +00:00
|
|
|
{
|
|
|
|
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)));
|
|
|
|
}
|
2018-04-22 21:40:38 +00:00
|
|
|
|
|
|
|
public static void clearRenderCache()
|
|
|
|
{
|
|
|
|
regionCache.invalidateAll();
|
|
|
|
regionCache.cleanUp();
|
|
|
|
}
|
2019-01-11 23:22:32 +00:00
|
|
|
|
|
|
|
private static HashMap<ResourceLocation, Supplier<NativeImage>> bufferedImageSuppliers = new HashMap<ResourceLocation, Supplier<NativeImage>>();
|
|
|
|
public static void registerImageLayerSupplier(ResourceLocation resourceLocation, Supplier<NativeImage> supplier)
|
|
|
|
{
|
|
|
|
bufferedImageSuppliers.put(resourceLocation, supplier);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
public static NativeImage getImageLayer(ResourceLocation resourceLocation, IResourceManager resourceManager) throws IOException
|
|
|
|
{
|
|
|
|
Supplier<NativeImage> supplier = bufferedImageSuppliers.get(resourceLocation);
|
|
|
|
if (supplier != null)
|
|
|
|
return supplier.get();
|
|
|
|
|
|
|
|
IResource iresource1 = resourceManager.getResource(resourceLocation);
|
|
|
|
return NativeImage.read(iresource1.getInputStream());
|
|
|
|
}
|
2011-07-15 23:04:10 +00:00
|
|
|
}
|