143 lines
6.0 KiB
Java
143 lines
6.0 KiB
Java
![]() |
/*
|
||
|
* Minecraft Forge
|
||
|
* Copyright (c) 2016-2020.
|
||
|
*
|
||
|
* 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
|
||
|
*/
|
||
|
|
||
|
package net.minecraftforge.client;
|
||
|
|
||
|
import net.minecraft.client.renderer.RenderState;
|
||
|
import net.minecraft.client.renderer.RenderType;
|
||
|
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||
|
import net.minecraft.util.ResourceLocation;
|
||
|
import net.minecraftforge.common.util.NonNullLazy;
|
||
|
import net.minecraftforge.common.util.NonNullSupplier;
|
||
|
import org.lwjgl.opengl.GL11;
|
||
|
|
||
|
public enum ForgeRenderTypes
|
||
|
{
|
||
|
/**
|
||
|
* A cached copy of {@link ForgeRenderTypes#getUnsortedTranslucent(ResourceLocation)}
|
||
|
* for use in item models and TileEntityRenderers that use the block/item atlas.
|
||
|
*/
|
||
|
ITEM_UNSORTED_TRANSLUCENT(()-> getUnsortedTranslucent(AtlasTexture.LOCATION_BLOCKS_TEXTURE)),
|
||
|
ITEM_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(AtlasTexture.LOCATION_BLOCKS_TEXTURE)),
|
||
|
ITEM_UNSORTED_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(AtlasTexture.LOCATION_BLOCKS_TEXTURE, false));
|
||
|
|
||
|
/**
|
||
|
* @return A RenderType fit for translucent item/entity rendering, but with depth sorting disabled.
|
||
|
*/
|
||
|
public static RenderType getUnsortedTranslucent(ResourceLocation textureLocation)
|
||
|
{
|
||
|
return Internal.unsortedTranslucent(textureLocation);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return A RenderType fit for translucent item/entity rendering, but with diffuse lighting disabled
|
||
|
* so that fullbright quads look correct.
|
||
|
*/
|
||
|
public static RenderType getUnlitTranslucent(ResourceLocation textureLocation)
|
||
|
{
|
||
|
return getUnlitTranslucent(textureLocation, true);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return A RenderType fit for translucent item/entity rendering, but with diffuse lighting disabled
|
||
|
* so that fullbright quads look correct.
|
||
|
* @param sortingEnabled If false, depth sorting will not be performed.
|
||
|
*/
|
||
|
public static RenderType getUnlitTranslucent(ResourceLocation textureLocation, boolean sortingEnabled)
|
||
|
{
|
||
|
return Internal.unlitTranslucent(textureLocation, sortingEnabled);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return Same as {@link RenderType#getEntityCutout(ResourceLocation)}, but with mipmapping enabled.
|
||
|
*/
|
||
|
public static RenderType getEntityCutoutMipped(ResourceLocation textureLocation)
|
||
|
{
|
||
|
return Internal.entityCutoutMipped(textureLocation);
|
||
|
}
|
||
|
|
||
|
// ----------------------------------------
|
||
|
// Implementation details below this line
|
||
|
// ----------------------------------------
|
||
|
|
||
|
private final NonNullSupplier<RenderType> renderTypeSupplier;
|
||
|
|
||
|
ForgeRenderTypes(NonNullSupplier<RenderType> renderTypeSupplier)
|
||
|
{
|
||
|
// Wrap in a Lazy<> to avoid running the supplier more than once.
|
||
|
this.renderTypeSupplier = NonNullLazy.of(renderTypeSupplier);
|
||
|
}
|
||
|
|
||
|
public RenderType get()
|
||
|
{
|
||
|
return renderTypeSupplier.get();
|
||
|
}
|
||
|
|
||
|
private static class Internal extends RenderType
|
||
|
{
|
||
|
private Internal(String name, VertexFormat fmt, int glMode, int size, boolean doCrumbling, boolean depthSorting, Runnable onEnable, Runnable onDisable)
|
||
|
{
|
||
|
super(name, fmt, glMode, size, doCrumbling, depthSorting, onEnable, onDisable);
|
||
|
throw new IllegalStateException("This class must not be instantiated");
|
||
|
}
|
||
|
|
||
|
public static RenderType unsortedTranslucent(ResourceLocation textureLocation)
|
||
|
{
|
||
|
final boolean sortingEnabled = false;
|
||
|
State renderState = State.getBuilder()
|
||
|
.texture(new TextureState(textureLocation, false, false))
|
||
|
.transparency(TRANSLUCENT_TRANSPARENCY)
|
||
|
.diffuseLighting(DIFFUSE_LIGHTING_ENABLED)
|
||
|
.alpha(DEFAULT_ALPHA)
|
||
|
.cull(CULL_DISABLED)
|
||
|
.lightmap(LIGHTMAP_ENABLED)
|
||
|
.overlay(OVERLAY_ENABLED)
|
||
|
.build(true);
|
||
|
return makeType("entity_unsorted_translucent", DefaultVertexFormats.ENTITY, GL11.GL_QUADS, 256, true, sortingEnabled, renderState);
|
||
|
}
|
||
|
|
||
|
public static RenderType unlitTranslucent(ResourceLocation textureLocation, boolean sortingEnabled)
|
||
|
{
|
||
|
State renderState = State.getBuilder()
|
||
|
.texture(new TextureState(textureLocation, false, false))
|
||
|
.transparency(TRANSLUCENT_TRANSPARENCY)
|
||
|
.alpha(DEFAULT_ALPHA)
|
||
|
.cull(CULL_DISABLED)
|
||
|
.lightmap(LIGHTMAP_ENABLED)
|
||
|
.overlay(OVERLAY_ENABLED)
|
||
|
.build(true);
|
||
|
return makeType("entity_unlit_translucent", DefaultVertexFormats.ENTITY, GL11.GL_QUADS, 256, true, sortingEnabled, renderState);
|
||
|
}
|
||
|
|
||
|
public static RenderType entityCutoutMipped(ResourceLocation locationIn) {
|
||
|
RenderType.State rendertype$state = RenderType.State.getBuilder()
|
||
|
.texture(new RenderState.TextureState(locationIn, false, true))
|
||
|
.transparency(NO_TRANSPARENCY)
|
||
|
.diffuseLighting(DIFFUSE_LIGHTING_ENABLED)
|
||
|
.alpha(DEFAULT_ALPHA)
|
||
|
.lightmap(LIGHTMAP_ENABLED)
|
||
|
.overlay(OVERLAY_ENABLED)
|
||
|
.build(true);
|
||
|
return makeType("entity_cutout_mipped", DefaultVertexFormats.ENTITY, 7, 256, true, false, rendertype$state);
|
||
|
}
|
||
|
}
|
||
|
}
|