base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,138 @@
package net.minecraft.client.renderer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.glu.GLU;
@SideOnly(Side.CLIENT)
public class ActiveRenderInfo
{
/** The current GL viewport */
private static final IntBuffer VIEWPORT = GLAllocation.createDirectIntBuffer(16);
/** The current GL modelview matrix */
private static final FloatBuffer MODELVIEW = GLAllocation.createDirectFloatBuffer(16);
/** The current GL projection matrix */
private static final FloatBuffer PROJECTION = GLAllocation.createDirectFloatBuffer(16);
/** The computed view object coordinates */
private static final FloatBuffer OBJECTCOORDS = GLAllocation.createDirectFloatBuffer(3);
private static Vec3d position = new Vec3d(0.0D, 0.0D, 0.0D);
/** The X component of the entity's yaw rotation */
private static float rotationX;
/** The combined X and Z components of the entity's pitch rotation */
private static float rotationXZ;
/** The Z component of the entity's yaw rotation */
private static float rotationZ;
/** The Y component (scaled along the Z axis) of the entity's pitch rotation */
private static float rotationYZ;
/** The Y component (scaled along the X axis) of the entity's pitch rotation */
private static float rotationXY;
/**
* Updates the current render info and camera location based on entity look angles and 1st/3rd person view mode
*/
public static void updateRenderInfo(EntityPlayer entityplayerIn, boolean p_74583_1_)
{
updateRenderInfo((Entity) entityplayerIn, p_74583_1_);
}
public static void updateRenderInfo(Entity entityplayerIn, boolean p_74583_1_)
{
GlStateManager.getFloat(2982, MODELVIEW);
GlStateManager.getFloat(2983, PROJECTION);
GlStateManager.glGetInteger(2978, VIEWPORT);
float f = (float)((VIEWPORT.get(0) + VIEWPORT.get(2)) / 2);
float f1 = (float)((VIEWPORT.get(1) + VIEWPORT.get(3)) / 2);
GLU.gluUnProject(f, f1, 0.0F, MODELVIEW, PROJECTION, VIEWPORT, OBJECTCOORDS);
position = new Vec3d((double)OBJECTCOORDS.get(0), (double)OBJECTCOORDS.get(1), (double)OBJECTCOORDS.get(2));
int i = p_74583_1_ ? 1 : 0;
float f2 = entityplayerIn.rotationPitch;
float f3 = entityplayerIn.rotationYaw;
rotationX = MathHelper.cos(f3 * 0.017453292F) * (float)(1 - i * 2);
rotationZ = MathHelper.sin(f3 * 0.017453292F) * (float)(1 - i * 2);
rotationYZ = -rotationZ * MathHelper.sin(f2 * 0.017453292F) * (float)(1 - i * 2);
rotationXY = rotationX * MathHelper.sin(f2 * 0.017453292F) * (float)(1 - i * 2);
rotationXZ = MathHelper.cos(f2 * 0.017453292F);
}
public static Vec3d projectViewFromEntity(Entity entityIn, double p_178806_1_)
{
double d0 = entityIn.prevPosX + (entityIn.posX - entityIn.prevPosX) * p_178806_1_;
double d1 = entityIn.prevPosY + (entityIn.posY - entityIn.prevPosY) * p_178806_1_;
double d2 = entityIn.prevPosZ + (entityIn.posZ - entityIn.prevPosZ) * p_178806_1_;
double d3 = d0 + position.x;
double d4 = d1 + position.y;
double d5 = d2 + position.z;
return new Vec3d(d3, d4, d5);
}
public static IBlockState getBlockStateAtEntityViewpoint(World worldIn, Entity entityIn, float p_186703_2_)
{
Vec3d vec3d = projectViewFromEntity(entityIn, (double)p_186703_2_);
BlockPos blockpos = new BlockPos(vec3d);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getMaterial().isLiquid())
{
float f = 0.0F;
if (iblockstate.getBlock() instanceof BlockLiquid)
{
f = BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()) - 0.11111111F;
}
float f1 = (float)(blockpos.getY() + 1) - f;
if (vec3d.y >= (double)f1)
{
iblockstate = worldIn.getBlockState(blockpos.up());
}
}
return iblockstate.getBlock().getStateAtViewpoint(iblockstate, worldIn, blockpos, vec3d);
}
public static float getRotationX()
{
return rotationX;
}
public static float getRotationXZ()
{
return rotationXZ;
}
public static float getRotationZ()
{
return rotationZ;
}
public static float getRotationYZ()
{
return rotationYZ;
}
public static float getRotationXY()
{
return rotationXY;
}
/* ======================================== FORGE START =====================================*/
/**
* Vector from render view entity position (corrected for partialTickTime) to the middle of screen
*/
public static Vec3d getCameraPosition()
{
return position;
}
}

View File

@@ -0,0 +1,111 @@
package net.minecraft.client.renderer;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.LayeredColorMaskTexture;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.tileentity.BannerPattern;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BannerTextures
{
/** An array of all the banner patterns that are being currently rendered */
public static final BannerTextures.Cache BANNER_DESIGNS = new BannerTextures.Cache("B", new ResourceLocation("textures/entity/banner_base.png"), "textures/entity/banner/");
/** An array of all the shield patterns that are being currently rendered */
public static final BannerTextures.Cache SHIELD_DESIGNS = new BannerTextures.Cache("S", new ResourceLocation("textures/entity/shield_base.png"), "textures/entity/shield/");
public static final ResourceLocation SHIELD_BASE_TEXTURE = new ResourceLocation("textures/entity/shield_base_nopattern.png");
public static final ResourceLocation BANNER_BASE_TEXTURE = new ResourceLocation("textures/entity/banner/base.png");
@SideOnly(Side.CLIENT)
public static class Cache
{
private final Map<String, BannerTextures.CacheEntry> cacheMap = Maps.<String, BannerTextures.CacheEntry>newLinkedHashMap();
private final ResourceLocation cacheResourceLocation;
private final String cacheResourceBase;
private final String cacheId;
public Cache(String id, ResourceLocation baseResource, String resourcePath)
{
this.cacheId = id;
this.cacheResourceLocation = baseResource;
this.cacheResourceBase = resourcePath;
}
@Nullable
public ResourceLocation getResourceLocation(String id, List<BannerPattern> patternList, List<EnumDyeColor> colorList)
{
if (id.isEmpty())
{
return null;
}
else
{
id = this.cacheId + id;
BannerTextures.CacheEntry bannertextures$cacheentry = this.cacheMap.get(id);
if (bannertextures$cacheentry == null)
{
if (this.cacheMap.size() >= 256 && !this.freeCacheSlot())
{
return BannerTextures.BANNER_BASE_TEXTURE;
}
List<String> list = Lists.<String>newArrayList();
for (BannerPattern bannerpattern : patternList)
{
list.add(this.cacheResourceBase + bannerpattern.getFileName() + ".png");
}
bannertextures$cacheentry = new BannerTextures.CacheEntry();
bannertextures$cacheentry.textureLocation = new ResourceLocation(id);
Minecraft.getMinecraft().getTextureManager().loadTexture(bannertextures$cacheentry.textureLocation, new LayeredColorMaskTexture(this.cacheResourceLocation, list, colorList));
this.cacheMap.put(id, bannertextures$cacheentry);
}
bannertextures$cacheentry.lastUseMillis = System.currentTimeMillis();
return bannertextures$cacheentry.textureLocation;
}
}
private boolean freeCacheSlot()
{
long i = System.currentTimeMillis();
Iterator<String> iterator = this.cacheMap.keySet().iterator();
while (iterator.hasNext())
{
String s = iterator.next();
BannerTextures.CacheEntry bannertextures$cacheentry = this.cacheMap.get(s);
if (i - bannertextures$cacheentry.lastUseMillis > 5000L)
{
Minecraft.getMinecraft().getTextureManager().deleteTexture(bannertextures$cacheentry.textureLocation);
iterator.remove();
return true;
}
}
return this.cacheMap.size() < 256;
}
}
@SideOnly(Side.CLIENT)
static class CacheEntry
{
public long lastUseMillis;
public ResourceLocation textureLocation;
private CacheEntry()
{
}
}
}

View File

@@ -0,0 +1,315 @@
package net.minecraft.client.renderer;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BlockFluidRenderer
{
private final BlockColors blockColors;
private final TextureAtlasSprite[] atlasSpritesLava = new TextureAtlasSprite[2];
private final TextureAtlasSprite[] atlasSpritesWater = new TextureAtlasSprite[2];
private TextureAtlasSprite atlasSpriteWaterOverlay;
public BlockFluidRenderer(BlockColors blockColorsIn)
{
this.blockColors = blockColorsIn;
this.initAtlasSprites();
}
protected void initAtlasSprites()
{
TextureMap texturemap = Minecraft.getMinecraft().getTextureMapBlocks();
this.atlasSpritesLava[0] = texturemap.getAtlasSprite("minecraft:blocks/lava_still");
this.atlasSpritesLava[1] = texturemap.getAtlasSprite("minecraft:blocks/lava_flow");
this.atlasSpritesWater[0] = texturemap.getAtlasSprite("minecraft:blocks/water_still");
this.atlasSpritesWater[1] = texturemap.getAtlasSprite("minecraft:blocks/water_flow");
this.atlasSpriteWaterOverlay = texturemap.getAtlasSprite("minecraft:blocks/water_overlay");
}
public boolean renderFluid(IBlockAccess blockAccess, IBlockState blockStateIn, BlockPos blockPosIn, BufferBuilder bufferBuilderIn)
{
BlockLiquid blockliquid = (BlockLiquid)blockStateIn.getBlock();
boolean flag = blockStateIn.getMaterial() == Material.LAVA;
TextureAtlasSprite[] atextureatlassprite = flag ? this.atlasSpritesLava : this.atlasSpritesWater;
int i = this.blockColors.colorMultiplier(blockStateIn, blockAccess, blockPosIn, 0);
float f = (float)(i >> 16 & 255) / 255.0F;
float f1 = (float)(i >> 8 & 255) / 255.0F;
float f2 = (float)(i & 255) / 255.0F;
boolean flag1 = blockStateIn.shouldSideBeRendered(blockAccess, blockPosIn, EnumFacing.UP);
boolean flag2 = blockStateIn.shouldSideBeRendered(blockAccess, blockPosIn, EnumFacing.DOWN);
boolean[] aboolean = new boolean[] {blockStateIn.shouldSideBeRendered(blockAccess, blockPosIn, EnumFacing.NORTH), blockStateIn.shouldSideBeRendered(blockAccess, blockPosIn, EnumFacing.SOUTH), blockStateIn.shouldSideBeRendered(blockAccess, blockPosIn, EnumFacing.WEST), blockStateIn.shouldSideBeRendered(blockAccess, blockPosIn, EnumFacing.EAST)};
if (!flag1 && !flag2 && !aboolean[0] && !aboolean[1] && !aboolean[2] && !aboolean[3])
{
return false;
}
else
{
boolean flag3 = false;
float f3 = 0.5F;
float f4 = 1.0F;
float f5 = 0.8F;
float f6 = 0.6F;
Material material = blockStateIn.getMaterial();
float f7 = this.getFluidHeight(blockAccess, blockPosIn, material);
float f8 = this.getFluidHeight(blockAccess, blockPosIn.south(), material);
float f9 = this.getFluidHeight(blockAccess, blockPosIn.east().south(), material);
float f10 = this.getFluidHeight(blockAccess, blockPosIn.east(), material);
double d0 = (double)blockPosIn.getX();
double d1 = (double)blockPosIn.getY();
double d2 = (double)blockPosIn.getZ();
float f11 = 0.001F;
if (flag1)
{
flag3 = true;
float f12 = BlockLiquid.getSlopeAngle(blockAccess, blockPosIn, material, blockStateIn);
TextureAtlasSprite textureatlassprite = f12 > -999.0F ? atextureatlassprite[1] : atextureatlassprite[0];
f7 -= 0.001F;
f8 -= 0.001F;
f9 -= 0.001F;
f10 -= 0.001F;
float f13;
float f14;
float f15;
float f16;
float f17;
float f18;
float f19;
float f20;
if (f12 < -999.0F)
{
f13 = textureatlassprite.getInterpolatedU(0.0D);
f17 = textureatlassprite.getInterpolatedV(0.0D);
f14 = f13;
f18 = textureatlassprite.getInterpolatedV(16.0D);
f15 = textureatlassprite.getInterpolatedU(16.0D);
f19 = f18;
f16 = f15;
f20 = f17;
}
else
{
float f21 = MathHelper.sin(f12) * 0.25F;
float f22 = MathHelper.cos(f12) * 0.25F;
float f23 = 8.0F;
f13 = textureatlassprite.getInterpolatedU((double)(8.0F + (-f22 - f21) * 16.0F));
f17 = textureatlassprite.getInterpolatedV((double)(8.0F + (-f22 + f21) * 16.0F));
f14 = textureatlassprite.getInterpolatedU((double)(8.0F + (-f22 + f21) * 16.0F));
f18 = textureatlassprite.getInterpolatedV((double)(8.0F + (f22 + f21) * 16.0F));
f15 = textureatlassprite.getInterpolatedU((double)(8.0F + (f22 + f21) * 16.0F));
f19 = textureatlassprite.getInterpolatedV((double)(8.0F + (f22 - f21) * 16.0F));
f16 = textureatlassprite.getInterpolatedU((double)(8.0F + (f22 - f21) * 16.0F));
f20 = textureatlassprite.getInterpolatedV((double)(8.0F + (-f22 - f21) * 16.0F));
}
int k2 = blockStateIn.getPackedLightmapCoords(blockAccess, blockPosIn);
int l2 = k2 >> 16 & 65535;
int i3 = k2 & 65535;
float f24 = 1.0F * f;
float f25 = 1.0F * f1;
float f26 = 1.0F * f2;
bufferBuilderIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex();
bufferBuilderIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex();
bufferBuilderIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex();
bufferBuilderIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex();
if (blockliquid.shouldRenderSides(blockAccess, blockPosIn.up()))
{
bufferBuilderIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex();
bufferBuilderIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex();
bufferBuilderIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex();
bufferBuilderIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex();
}
}
if (flag2)
{
float f35 = atextureatlassprite[0].getMinU();
float f36 = atextureatlassprite[0].getMaxU();
float f37 = atextureatlassprite[0].getMinV();
float f38 = atextureatlassprite[0].getMaxV();
int l1 = blockStateIn.getPackedLightmapCoords(blockAccess, blockPosIn.down());
int i2 = l1 >> 16 & 65535;
int j2 = l1 & 65535;
bufferBuilderIn.pos(d0, d1, d2 + 1.0D).color(0.5F, 0.5F, 0.5F, 1.0F).tex((double)f35, (double)f38).lightmap(i2, j2).endVertex();
bufferBuilderIn.pos(d0, d1, d2).color(0.5F, 0.5F, 0.5F, 1.0F).tex((double)f35, (double)f37).lightmap(i2, j2).endVertex();
bufferBuilderIn.pos(d0 + 1.0D, d1, d2).color(0.5F, 0.5F, 0.5F, 1.0F).tex((double)f36, (double)f37).lightmap(i2, j2).endVertex();
bufferBuilderIn.pos(d0 + 1.0D, d1, d2 + 1.0D).color(0.5F, 0.5F, 0.5F, 1.0F).tex((double)f36, (double)f38).lightmap(i2, j2).endVertex();
flag3 = true;
}
for (int i1 = 0; i1 < 4; ++i1)
{
int j1 = 0;
int k1 = 0;
if (i1 == 0)
{
--k1;
}
if (i1 == 1)
{
++k1;
}
if (i1 == 2)
{
--j1;
}
if (i1 == 3)
{
++j1;
}
BlockPos blockpos = blockPosIn.add(j1, 0, k1);
TextureAtlasSprite textureatlassprite1 = atextureatlassprite[1];
if (!flag)
{
IBlockState state = blockAccess.getBlockState(blockpos);
if (state.getBlockFaceShape(blockAccess, blockpos, EnumFacing.VALUES[i1+2].getOpposite()) == net.minecraft.block.state.BlockFaceShape.SOLID)
{
textureatlassprite1 = this.atlasSpriteWaterOverlay;
}
}
if (aboolean[i1])
{
float f39;
float f40;
double d3;
double d4;
double d5;
double d6;
if (i1 == 0)
{
f39 = f7;
f40 = f10;
d3 = d0;
d5 = d0 + 1.0D;
d4 = d2 + 0.0010000000474974513D;
d6 = d2 + 0.0010000000474974513D;
}
else if (i1 == 1)
{
f39 = f9;
f40 = f8;
d3 = d0 + 1.0D;
d5 = d0;
d4 = d2 + 1.0D - 0.0010000000474974513D;
d6 = d2 + 1.0D - 0.0010000000474974513D;
}
else if (i1 == 2)
{
f39 = f8;
f40 = f7;
d3 = d0 + 0.0010000000474974513D;
d5 = d0 + 0.0010000000474974513D;
d4 = d2 + 1.0D;
d6 = d2;
}
else
{
f39 = f10;
f40 = f9;
d3 = d0 + 1.0D - 0.0010000000474974513D;
d5 = d0 + 1.0D - 0.0010000000474974513D;
d4 = d2;
d6 = d2 + 1.0D;
}
flag3 = true;
float f41 = textureatlassprite1.getInterpolatedU(0.0D);
float f27 = textureatlassprite1.getInterpolatedU(8.0D);
float f28 = textureatlassprite1.getInterpolatedV((double)((1.0F - f39) * 16.0F * 0.5F));
float f29 = textureatlassprite1.getInterpolatedV((double)((1.0F - f40) * 16.0F * 0.5F));
float f30 = textureatlassprite1.getInterpolatedV(8.0D);
int j = blockStateIn.getPackedLightmapCoords(blockAccess, blockpos);
int k = j >> 16 & 65535;
int l = j & 65535;
float f31 = i1 < 2 ? 0.8F : 0.6F;
float f32 = 1.0F * f31 * f;
float f33 = 1.0F * f31 * f1;
float f34 = 1.0F * f31 * f2;
bufferBuilderIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f28).lightmap(k, l).endVertex();
bufferBuilderIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f29).lightmap(k, l).endVertex();
bufferBuilderIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f30).lightmap(k, l).endVertex();
bufferBuilderIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f30).lightmap(k, l).endVertex();
if (textureatlassprite1 != this.atlasSpriteWaterOverlay)
{
bufferBuilderIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f30).lightmap(k, l).endVertex();
bufferBuilderIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f30).lightmap(k, l).endVertex();
bufferBuilderIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f29).lightmap(k, l).endVertex();
bufferBuilderIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f28).lightmap(k, l).endVertex();
}
}
}
return flag3;
}
}
private float getFluidHeight(IBlockAccess blockAccess, BlockPos blockPosIn, Material blockMaterial)
{
int i = 0;
float f = 0.0F;
for (int j = 0; j < 4; ++j)
{
BlockPos blockpos = blockPosIn.add(-(j & 1), 0, -(j >> 1 & 1));
if (blockAccess.getBlockState(blockpos.up()).getMaterial() == blockMaterial)
{
return 1.0F;
}
IBlockState iblockstate = blockAccess.getBlockState(blockpos);
Material material = iblockstate.getMaterial();
if (material != blockMaterial)
{
if (!material.isSolid())
{
++f;
++i;
}
}
else
{
int k = ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue();
if (k >= 8 || k == 0)
{
f += BlockLiquid.getLiquidHeightPercent(k) * 10.0F;
i += 10;
}
f += BlockLiquid.getLiquidHeightPercent(k);
++i;
}
}
return 1.0F - f / (float)i;
}
}

View File

@@ -0,0 +1,656 @@
package net.minecraft.client.renderer;
import java.util.BitSet;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ReportedException;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BlockModelRenderer
{
private final BlockColors blockColors;
public BlockModelRenderer(BlockColors blockColorsIn)
{
this.blockColors = blockColorsIn;
}
public boolean renderModel(IBlockAccess blockAccessIn, IBakedModel modelIn, IBlockState blockStateIn, BlockPos blockPosIn, BufferBuilder buffer, boolean checkSides)
{
return this.renderModel(blockAccessIn, modelIn, blockStateIn, blockPosIn, buffer, checkSides, MathHelper.getPositionRandom(blockPosIn));
}
public boolean renderModel(IBlockAccess worldIn, IBakedModel modelIn, IBlockState stateIn, BlockPos posIn, BufferBuilder buffer, boolean checkSides, long rand)
{
boolean flag = Minecraft.isAmbientOcclusionEnabled() && stateIn.getLightValue(worldIn, posIn) == 0 && modelIn.isAmbientOcclusion(stateIn);
try
{
return flag ? this.renderModelSmooth(worldIn, modelIn, stateIn, posIn, buffer, checkSides, rand) : this.renderModelFlat(worldIn, modelIn, stateIn, posIn, buffer, checkSides, rand);
}
catch (Throwable throwable)
{
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Tesselating block model");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Block model being tesselated");
CrashReportCategory.addBlockInfo(crashreportcategory, posIn, stateIn);
crashreportcategory.addCrashSection("Using AO", Boolean.valueOf(flag));
throw new ReportedException(crashreport);
}
}
public boolean renderModelSmooth(IBlockAccess worldIn, IBakedModel modelIn, IBlockState stateIn, BlockPos posIn, BufferBuilder buffer, boolean checkSides, long rand)
{
boolean flag = false;
float[] afloat = new float[EnumFacing.values().length * 2];
BitSet bitset = new BitSet(3);
BlockModelRenderer.AmbientOcclusionFace blockmodelrenderer$ambientocclusionface = new BlockModelRenderer.AmbientOcclusionFace();
for (EnumFacing enumfacing : EnumFacing.values())
{
List<BakedQuad> list = modelIn.getQuads(stateIn, enumfacing, rand);
if (!list.isEmpty() && (!checkSides || stateIn.shouldSideBeRendered(worldIn, posIn, enumfacing)))
{
this.renderQuadsSmooth(worldIn, stateIn, posIn, buffer, list, afloat, bitset, blockmodelrenderer$ambientocclusionface);
flag = true;
}
}
List<BakedQuad> list1 = modelIn.getQuads(stateIn, (EnumFacing)null, rand);
if (!list1.isEmpty())
{
this.renderQuadsSmooth(worldIn, stateIn, posIn, buffer, list1, afloat, bitset, blockmodelrenderer$ambientocclusionface);
flag = true;
}
return flag;
}
public boolean renderModelFlat(IBlockAccess worldIn, IBakedModel modelIn, IBlockState stateIn, BlockPos posIn, BufferBuilder buffer, boolean checkSides, long rand)
{
boolean flag = false;
BitSet bitset = new BitSet(3);
for (EnumFacing enumfacing : EnumFacing.values())
{
List<BakedQuad> list = modelIn.getQuads(stateIn, enumfacing, rand);
if (!list.isEmpty() && (!checkSides || stateIn.shouldSideBeRendered(worldIn, posIn, enumfacing)))
{
int i = stateIn.getPackedLightmapCoords(worldIn, posIn.offset(enumfacing));
this.renderQuadsFlat(worldIn, stateIn, posIn, i, false, buffer, list, bitset);
flag = true;
}
}
List<BakedQuad> list1 = modelIn.getQuads(stateIn, (EnumFacing)null, rand);
if (!list1.isEmpty())
{
this.renderQuadsFlat(worldIn, stateIn, posIn, -1, true, buffer, list1, bitset);
flag = true;
}
return flag;
}
private void renderQuadsSmooth(IBlockAccess blockAccessIn, IBlockState stateIn, BlockPos posIn, BufferBuilder buffer, List<BakedQuad> list, float[] quadBounds, BitSet bitSet, BlockModelRenderer.AmbientOcclusionFace aoFace)
{
Vec3d vec3d = stateIn.getOffset(blockAccessIn, posIn);
double d0 = (double)posIn.getX() + vec3d.x;
double d1 = (double)posIn.getY() + vec3d.y;
double d2 = (double)posIn.getZ() + vec3d.z;
int i = 0;
for (int j = list.size(); i < j; ++i)
{
BakedQuad bakedquad = list.get(i);
this.fillQuadBounds(stateIn, bakedquad.getVertexData(), bakedquad.getFace(), quadBounds, bitSet);
aoFace.updateVertexBrightness(blockAccessIn, stateIn, posIn, bakedquad.getFace(), quadBounds, bitSet);
buffer.addVertexData(bakedquad.getVertexData());
buffer.putBrightness4(aoFace.vertexBrightness[0], aoFace.vertexBrightness[1], aoFace.vertexBrightness[2], aoFace.vertexBrightness[3]);
if(bakedquad.shouldApplyDiffuseLighting())
{
float diffuse = net.minecraftforge.client.model.pipeline.LightUtil.diffuseLight(bakedquad.getFace());
aoFace.vertexColorMultiplier[0] *= diffuse;
aoFace.vertexColorMultiplier[1] *= diffuse;
aoFace.vertexColorMultiplier[2] *= diffuse;
aoFace.vertexColorMultiplier[3] *= diffuse;
}
if (bakedquad.hasTintIndex())
{
int k = this.blockColors.colorMultiplier(stateIn, blockAccessIn, posIn, bakedquad.getTintIndex());
if (EntityRenderer.anaglyphEnable)
{
k = TextureUtil.anaglyphColor(k);
}
float f = (float)(k >> 16 & 255) / 255.0F;
float f1 = (float)(k >> 8 & 255) / 255.0F;
float f2 = (float)(k & 255) / 255.0F;
buffer.putColorMultiplier(aoFace.vertexColorMultiplier[0] * f, aoFace.vertexColorMultiplier[0] * f1, aoFace.vertexColorMultiplier[0] * f2, 4);
buffer.putColorMultiplier(aoFace.vertexColorMultiplier[1] * f, aoFace.vertexColorMultiplier[1] * f1, aoFace.vertexColorMultiplier[1] * f2, 3);
buffer.putColorMultiplier(aoFace.vertexColorMultiplier[2] * f, aoFace.vertexColorMultiplier[2] * f1, aoFace.vertexColorMultiplier[2] * f2, 2);
buffer.putColorMultiplier(aoFace.vertexColorMultiplier[3] * f, aoFace.vertexColorMultiplier[3] * f1, aoFace.vertexColorMultiplier[3] * f2, 1);
}
else
{
buffer.putColorMultiplier(aoFace.vertexColorMultiplier[0], aoFace.vertexColorMultiplier[0], aoFace.vertexColorMultiplier[0], 4);
buffer.putColorMultiplier(aoFace.vertexColorMultiplier[1], aoFace.vertexColorMultiplier[1], aoFace.vertexColorMultiplier[1], 3);
buffer.putColorMultiplier(aoFace.vertexColorMultiplier[2], aoFace.vertexColorMultiplier[2], aoFace.vertexColorMultiplier[2], 2);
buffer.putColorMultiplier(aoFace.vertexColorMultiplier[3], aoFace.vertexColorMultiplier[3], aoFace.vertexColorMultiplier[3], 1);
}
buffer.putPosition(d0, d1, d2);
}
}
private void fillQuadBounds(IBlockState stateIn, int[] vertexData, EnumFacing face, @Nullable float[] quadBounds, BitSet boundsFlags)
{
float f = 32.0F;
float f1 = 32.0F;
float f2 = 32.0F;
float f3 = -32.0F;
float f4 = -32.0F;
float f5 = -32.0F;
for (int i = 0; i < 4; ++i)
{
float f6 = Float.intBitsToFloat(vertexData[i * 7]);
float f7 = Float.intBitsToFloat(vertexData[i * 7 + 1]);
float f8 = Float.intBitsToFloat(vertexData[i * 7 + 2]);
f = Math.min(f, f6);
f1 = Math.min(f1, f7);
f2 = Math.min(f2, f8);
f3 = Math.max(f3, f6);
f4 = Math.max(f4, f7);
f5 = Math.max(f5, f8);
}
if (quadBounds != null)
{
quadBounds[EnumFacing.WEST.getIndex()] = f;
quadBounds[EnumFacing.EAST.getIndex()] = f3;
quadBounds[EnumFacing.DOWN.getIndex()] = f1;
quadBounds[EnumFacing.UP.getIndex()] = f4;
quadBounds[EnumFacing.NORTH.getIndex()] = f2;
quadBounds[EnumFacing.SOUTH.getIndex()] = f5;
int j = EnumFacing.values().length;
quadBounds[EnumFacing.WEST.getIndex() + j] = 1.0F - f;
quadBounds[EnumFacing.EAST.getIndex() + j] = 1.0F - f3;
quadBounds[EnumFacing.DOWN.getIndex() + j] = 1.0F - f1;
quadBounds[EnumFacing.UP.getIndex() + j] = 1.0F - f4;
quadBounds[EnumFacing.NORTH.getIndex() + j] = 1.0F - f2;
quadBounds[EnumFacing.SOUTH.getIndex() + j] = 1.0F - f5;
}
float f9 = 1.0E-4F;
float f10 = 0.9999F;
switch (face)
{
case DOWN:
boundsFlags.set(1, f >= 1.0E-4F || f2 >= 1.0E-4F || f3 <= 0.9999F || f5 <= 0.9999F);
boundsFlags.set(0, (f1 < 1.0E-4F || stateIn.isFullCube()) && f1 == f4);
break;
case UP:
boundsFlags.set(1, f >= 1.0E-4F || f2 >= 1.0E-4F || f3 <= 0.9999F || f5 <= 0.9999F);
boundsFlags.set(0, (f4 > 0.9999F || stateIn.isFullCube()) && f1 == f4);
break;
case NORTH:
boundsFlags.set(1, f >= 1.0E-4F || f1 >= 1.0E-4F || f3 <= 0.9999F || f4 <= 0.9999F);
boundsFlags.set(0, (f2 < 1.0E-4F || stateIn.isFullCube()) && f2 == f5);
break;
case SOUTH:
boundsFlags.set(1, f >= 1.0E-4F || f1 >= 1.0E-4F || f3 <= 0.9999F || f4 <= 0.9999F);
boundsFlags.set(0, (f5 > 0.9999F || stateIn.isFullCube()) && f2 == f5);
break;
case WEST:
boundsFlags.set(1, f1 >= 1.0E-4F || f2 >= 1.0E-4F || f4 <= 0.9999F || f5 <= 0.9999F);
boundsFlags.set(0, (f < 1.0E-4F || stateIn.isFullCube()) && f == f3);
break;
case EAST:
boundsFlags.set(1, f1 >= 1.0E-4F || f2 >= 1.0E-4F || f4 <= 0.9999F || f5 <= 0.9999F);
boundsFlags.set(0, (f3 > 0.9999F || stateIn.isFullCube()) && f == f3);
}
}
private void renderQuadsFlat(IBlockAccess blockAccessIn, IBlockState stateIn, BlockPos posIn, int brightnessIn, boolean ownBrightness, BufferBuilder buffer, List<BakedQuad> list, BitSet bitSet)
{
Vec3d vec3d = stateIn.getOffset(blockAccessIn, posIn);
double d0 = (double)posIn.getX() + vec3d.x;
double d1 = (double)posIn.getY() + vec3d.y;
double d2 = (double)posIn.getZ() + vec3d.z;
int i = 0;
for (int j = list.size(); i < j; ++i)
{
BakedQuad bakedquad = list.get(i);
if (ownBrightness)
{
this.fillQuadBounds(stateIn, bakedquad.getVertexData(), bakedquad.getFace(), (float[])null, bitSet);
BlockPos blockpos = bitSet.get(0) ? posIn.offset(bakedquad.getFace()) : posIn;
brightnessIn = stateIn.getPackedLightmapCoords(blockAccessIn, blockpos);
}
buffer.addVertexData(bakedquad.getVertexData());
buffer.putBrightness4(brightnessIn, brightnessIn, brightnessIn, brightnessIn);
if (bakedquad.hasTintIndex())
{
int k = this.blockColors.colorMultiplier(stateIn, blockAccessIn, posIn, bakedquad.getTintIndex());
if (EntityRenderer.anaglyphEnable)
{
k = TextureUtil.anaglyphColor(k);
}
float f = (float)(k >> 16 & 255) / 255.0F;
float f1 = (float)(k >> 8 & 255) / 255.0F;
float f2 = (float)(k & 255) / 255.0F;
if(bakedquad.shouldApplyDiffuseLighting())
{
float diffuse = net.minecraftforge.client.model.pipeline.LightUtil.diffuseLight(bakedquad.getFace());
f *= diffuse;
f1 *= diffuse;
f2 *= diffuse;
}
buffer.putColorMultiplier(f, f1, f2, 4);
buffer.putColorMultiplier(f, f1, f2, 3);
buffer.putColorMultiplier(f, f1, f2, 2);
buffer.putColorMultiplier(f, f1, f2, 1);
}
else if(bakedquad.shouldApplyDiffuseLighting())
{
float diffuse = net.minecraftforge.client.model.pipeline.LightUtil.diffuseLight(bakedquad.getFace());
buffer.putColorMultiplier(diffuse, diffuse, diffuse, 4);
buffer.putColorMultiplier(diffuse, diffuse, diffuse, 3);
buffer.putColorMultiplier(diffuse, diffuse, diffuse, 2);
buffer.putColorMultiplier(diffuse, diffuse, diffuse, 1);
}
buffer.putPosition(d0, d1, d2);
}
}
public void renderModelBrightnessColor(IBakedModel bakedModel, float p_178262_2_, float red, float green, float blue)
{
this.renderModelBrightnessColor((IBlockState)null, bakedModel, p_178262_2_, red, green, blue);
}
public void renderModelBrightnessColor(IBlockState state, IBakedModel p_187495_2_, float p_187495_3_, float p_187495_4_, float p_187495_5_, float p_187495_6_)
{
for (EnumFacing enumfacing : EnumFacing.values())
{
this.renderModelBrightnessColorQuads(p_187495_3_, p_187495_4_, p_187495_5_, p_187495_6_, p_187495_2_.getQuads(state, enumfacing, 0L));
}
this.renderModelBrightnessColorQuads(p_187495_3_, p_187495_4_, p_187495_5_, p_187495_6_, p_187495_2_.getQuads(state, (EnumFacing)null, 0L));
}
public void renderModelBrightness(IBakedModel model, IBlockState state, float brightness, boolean p_178266_4_)
{
Block block = state.getBlock();
GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
int i = this.blockColors.colorMultiplier(state, (IBlockAccess)null, (BlockPos)null, 0);
if (EntityRenderer.anaglyphEnable)
{
i = TextureUtil.anaglyphColor(i);
}
float f = (float)(i >> 16 & 255) / 255.0F;
float f1 = (float)(i >> 8 & 255) / 255.0F;
float f2 = (float)(i & 255) / 255.0F;
if (!p_178266_4_)
{
GlStateManager.color(brightness, brightness, brightness, 1.0F);
}
this.renderModelBrightnessColor(state, model, brightness, f, f1, f2);
}
private void renderModelBrightnessColorQuads(float brightness, float red, float green, float blue, List<BakedQuad> listQuads)
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
int i = 0;
for (int j = listQuads.size(); i < j; ++i)
{
BakedQuad bakedquad = listQuads.get(i);
bufferbuilder.begin(7, DefaultVertexFormats.ITEM);
bufferbuilder.addVertexData(bakedquad.getVertexData());
if (bakedquad.hasTintIndex())
{
bufferbuilder.putColorRGB_F4(red * brightness, green * brightness, blue * brightness);
}
else
{
bufferbuilder.putColorRGB_F4(brightness, brightness, brightness);
}
Vec3i vec3i = bakedquad.getFace().getDirectionVec();
bufferbuilder.putNormal((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ());
tessellator.draw();
}
}
@SideOnly(Side.CLIENT)
class AmbientOcclusionFace
{
private final float[] vertexColorMultiplier = new float[4];
private final int[] vertexBrightness = new int[4];
public void updateVertexBrightness(IBlockAccess worldIn, IBlockState state, BlockPos centerPos, EnumFacing direction, float[] faceShape, BitSet shapeState)
{
BlockPos blockpos = shapeState.get(0) ? centerPos.offset(direction) : centerPos;
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
BlockModelRenderer.EnumNeighborInfo blockmodelrenderer$enumneighborinfo = BlockModelRenderer.EnumNeighborInfo.getNeighbourInfo(direction);
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos1 = BlockPos.PooledMutableBlockPos.retain(blockpos).move(blockmodelrenderer$enumneighborinfo.corners[0]);
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos2 = BlockPos.PooledMutableBlockPos.retain(blockpos).move(blockmodelrenderer$enumneighborinfo.corners[1]);
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos3 = BlockPos.PooledMutableBlockPos.retain(blockpos).move(blockmodelrenderer$enumneighborinfo.corners[2]);
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos4 = BlockPos.PooledMutableBlockPos.retain(blockpos).move(blockmodelrenderer$enumneighborinfo.corners[3]);
int i = state.getPackedLightmapCoords(worldIn, blockpos$pooledmutableblockpos1);
int j = state.getPackedLightmapCoords(worldIn, blockpos$pooledmutableblockpos2);
int k = state.getPackedLightmapCoords(worldIn, blockpos$pooledmutableblockpos3);
int l = state.getPackedLightmapCoords(worldIn, blockpos$pooledmutableblockpos4);
float f = worldIn.getBlockState(blockpos$pooledmutableblockpos1).getAmbientOcclusionLightValue();
float f1 = worldIn.getBlockState(blockpos$pooledmutableblockpos2).getAmbientOcclusionLightValue();
float f2 = worldIn.getBlockState(blockpos$pooledmutableblockpos3).getAmbientOcclusionLightValue();
float f3 = worldIn.getBlockState(blockpos$pooledmutableblockpos4).getAmbientOcclusionLightValue();
boolean flag = worldIn.getBlockState(blockpos$pooledmutableblockpos.setPos(blockpos$pooledmutableblockpos1).move(direction)).isTranslucent();
boolean flag1 = worldIn.getBlockState(blockpos$pooledmutableblockpos.setPos(blockpos$pooledmutableblockpos2).move(direction)).isTranslucent();
boolean flag2 = worldIn.getBlockState(blockpos$pooledmutableblockpos.setPos(blockpos$pooledmutableblockpos3).move(direction)).isTranslucent();
boolean flag3 = worldIn.getBlockState(blockpos$pooledmutableblockpos.setPos(blockpos$pooledmutableblockpos4).move(direction)).isTranslucent();
float f4;
int i1;
if (!flag2 && !flag)
{
f4 = f;
i1 = i;
}
else
{
BlockPos blockpos1 = blockpos$pooledmutableblockpos.setPos(blockpos$pooledmutableblockpos1).move(blockmodelrenderer$enumneighborinfo.corners[2]);
f4 = worldIn.getBlockState(blockpos1).getAmbientOcclusionLightValue();
i1 = state.getPackedLightmapCoords(worldIn, blockpos1);
}
float f5;
int j1;
if (!flag3 && !flag)
{
f5 = f;
j1 = i;
}
else
{
BlockPos blockpos2 = blockpos$pooledmutableblockpos.setPos(blockpos$pooledmutableblockpos1).move(blockmodelrenderer$enumneighborinfo.corners[3]);
f5 = worldIn.getBlockState(blockpos2).getAmbientOcclusionLightValue();
j1 = state.getPackedLightmapCoords(worldIn, blockpos2);
}
float f6;
int k1;
if (!flag2 && !flag1)
{
f6 = f1;
k1 = j;
}
else
{
BlockPos blockpos3 = blockpos$pooledmutableblockpos.setPos(blockpos$pooledmutableblockpos2).move(blockmodelrenderer$enumneighborinfo.corners[2]);
f6 = worldIn.getBlockState(blockpos3).getAmbientOcclusionLightValue();
k1 = state.getPackedLightmapCoords(worldIn, blockpos3);
}
float f7;
int l1;
if (!flag3 && !flag1)
{
f7 = f1;
l1 = j;
}
else
{
BlockPos blockpos4 = blockpos$pooledmutableblockpos.setPos(blockpos$pooledmutableblockpos2).move(blockmodelrenderer$enumneighborinfo.corners[3]);
f7 = worldIn.getBlockState(blockpos4).getAmbientOcclusionLightValue();
l1 = state.getPackedLightmapCoords(worldIn, blockpos4);
}
int i3 = state.getPackedLightmapCoords(worldIn, centerPos);
if (shapeState.get(0) || !worldIn.getBlockState(centerPos.offset(direction)).isOpaqueCube())
{
i3 = state.getPackedLightmapCoords(worldIn, centerPos.offset(direction));
}
float f8 = shapeState.get(0) ? worldIn.getBlockState(blockpos).getAmbientOcclusionLightValue() : worldIn.getBlockState(centerPos).getAmbientOcclusionLightValue();
BlockModelRenderer.VertexTranslations blockmodelrenderer$vertextranslations = BlockModelRenderer.VertexTranslations.getVertexTranslations(direction);
blockpos$pooledmutableblockpos.release();
blockpos$pooledmutableblockpos1.release();
blockpos$pooledmutableblockpos2.release();
blockpos$pooledmutableblockpos3.release();
blockpos$pooledmutableblockpos4.release();
if (shapeState.get(1) && blockmodelrenderer$enumneighborinfo.doNonCubicWeight)
{
float f29 = (f3 + f + f5 + f8) * 0.25F;
float f30 = (f2 + f + f4 + f8) * 0.25F;
float f31 = (f2 + f1 + f6 + f8) * 0.25F;
float f32 = (f3 + f1 + f7 + f8) * 0.25F;
float f13 = faceShape[blockmodelrenderer$enumneighborinfo.vert0Weights[0].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert0Weights[1].shape];
float f14 = faceShape[blockmodelrenderer$enumneighborinfo.vert0Weights[2].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert0Weights[3].shape];
float f15 = faceShape[blockmodelrenderer$enumneighborinfo.vert0Weights[4].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert0Weights[5].shape];
float f16 = faceShape[blockmodelrenderer$enumneighborinfo.vert0Weights[6].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert0Weights[7].shape];
float f17 = faceShape[blockmodelrenderer$enumneighborinfo.vert1Weights[0].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert1Weights[1].shape];
float f18 = faceShape[blockmodelrenderer$enumneighborinfo.vert1Weights[2].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert1Weights[3].shape];
float f19 = faceShape[blockmodelrenderer$enumneighborinfo.vert1Weights[4].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert1Weights[5].shape];
float f20 = faceShape[blockmodelrenderer$enumneighborinfo.vert1Weights[6].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert1Weights[7].shape];
float f21 = faceShape[blockmodelrenderer$enumneighborinfo.vert2Weights[0].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert2Weights[1].shape];
float f22 = faceShape[blockmodelrenderer$enumneighborinfo.vert2Weights[2].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert2Weights[3].shape];
float f23 = faceShape[blockmodelrenderer$enumneighborinfo.vert2Weights[4].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert2Weights[5].shape];
float f24 = faceShape[blockmodelrenderer$enumneighborinfo.vert2Weights[6].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert2Weights[7].shape];
float f25 = faceShape[blockmodelrenderer$enumneighborinfo.vert3Weights[0].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert3Weights[1].shape];
float f26 = faceShape[blockmodelrenderer$enumneighborinfo.vert3Weights[2].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert3Weights[3].shape];
float f27 = faceShape[blockmodelrenderer$enumneighborinfo.vert3Weights[4].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert3Weights[5].shape];
float f28 = faceShape[blockmodelrenderer$enumneighborinfo.vert3Weights[6].shape] * faceShape[blockmodelrenderer$enumneighborinfo.vert3Weights[7].shape];
this.vertexColorMultiplier[blockmodelrenderer$vertextranslations.vert0] = f29 * f13 + f30 * f14 + f31 * f15 + f32 * f16;
this.vertexColorMultiplier[blockmodelrenderer$vertextranslations.vert1] = f29 * f17 + f30 * f18 + f31 * f19 + f32 * f20;
this.vertexColorMultiplier[blockmodelrenderer$vertextranslations.vert2] = f29 * f21 + f30 * f22 + f31 * f23 + f32 * f24;
this.vertexColorMultiplier[blockmodelrenderer$vertextranslations.vert3] = f29 * f25 + f30 * f26 + f31 * f27 + f32 * f28;
int i2 = this.getAoBrightness(l, i, j1, i3);
int j2 = this.getAoBrightness(k, i, i1, i3);
int k2 = this.getAoBrightness(k, j, k1, i3);
int l2 = this.getAoBrightness(l, j, l1, i3);
this.vertexBrightness[blockmodelrenderer$vertextranslations.vert0] = this.getVertexBrightness(i2, j2, k2, l2, f13, f14, f15, f16);
this.vertexBrightness[blockmodelrenderer$vertextranslations.vert1] = this.getVertexBrightness(i2, j2, k2, l2, f17, f18, f19, f20);
this.vertexBrightness[blockmodelrenderer$vertextranslations.vert2] = this.getVertexBrightness(i2, j2, k2, l2, f21, f22, f23, f24);
this.vertexBrightness[blockmodelrenderer$vertextranslations.vert3] = this.getVertexBrightness(i2, j2, k2, l2, f25, f26, f27, f28);
}
else
{
float f9 = (f3 + f + f5 + f8) * 0.25F;
float f10 = (f2 + f + f4 + f8) * 0.25F;
float f11 = (f2 + f1 + f6 + f8) * 0.25F;
float f12 = (f3 + f1 + f7 + f8) * 0.25F;
this.vertexBrightness[blockmodelrenderer$vertextranslations.vert0] = this.getAoBrightness(l, i, j1, i3);
this.vertexBrightness[blockmodelrenderer$vertextranslations.vert1] = this.getAoBrightness(k, i, i1, i3);
this.vertexBrightness[blockmodelrenderer$vertextranslations.vert2] = this.getAoBrightness(k, j, k1, i3);
this.vertexBrightness[blockmodelrenderer$vertextranslations.vert3] = this.getAoBrightness(l, j, l1, i3);
this.vertexColorMultiplier[blockmodelrenderer$vertextranslations.vert0] = f9;
this.vertexColorMultiplier[blockmodelrenderer$vertextranslations.vert1] = f10;
this.vertexColorMultiplier[blockmodelrenderer$vertextranslations.vert2] = f11;
this.vertexColorMultiplier[blockmodelrenderer$vertextranslations.vert3] = f12;
}
}
/**
* Get ambient occlusion brightness
*/
private int getAoBrightness(int br1, int br2, int br3, int br4)
{
if (br1 == 0)
{
br1 = br4;
}
if (br2 == 0)
{
br2 = br4;
}
if (br3 == 0)
{
br3 = br4;
}
return br1 + br2 + br3 + br4 >> 2 & 16711935;
}
private int getVertexBrightness(int p_178203_1_, int p_178203_2_, int p_178203_3_, int p_178203_4_, float p_178203_5_, float p_178203_6_, float p_178203_7_, float p_178203_8_)
{
int i = (int)((float)(p_178203_1_ >> 16 & 255) * p_178203_5_ + (float)(p_178203_2_ >> 16 & 255) * p_178203_6_ + (float)(p_178203_3_ >> 16 & 255) * p_178203_7_ + (float)(p_178203_4_ >> 16 & 255) * p_178203_8_) & 255;
int j = (int)((float)(p_178203_1_ & 255) * p_178203_5_ + (float)(p_178203_2_ & 255) * p_178203_6_ + (float)(p_178203_3_ & 255) * p_178203_7_ + (float)(p_178203_4_ & 255) * p_178203_8_) & 255;
return i << 16 | j;
}
}
@SideOnly(Side.CLIENT)
public static enum EnumNeighborInfo
{
DOWN(new EnumFacing[]{EnumFacing.WEST, EnumFacing.EAST, EnumFacing.NORTH, EnumFacing.SOUTH}, 0.5F, true, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.SOUTH, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.SOUTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.NORTH, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.NORTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.NORTH, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.NORTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.SOUTH, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.SOUTH}),
UP(new EnumFacing[]{EnumFacing.EAST, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH}, 1.0F, true, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.SOUTH, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.SOUTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.NORTH, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.NORTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.NORTH, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.NORTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.SOUTH, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.SOUTH}),
NORTH(new EnumFacing[]{EnumFacing.UP, EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.WEST}, 0.8F, true, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.FLIP_WEST}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.FLIP_EAST}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.FLIP_EAST}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.FLIP_WEST}),
SOUTH(new EnumFacing[]{EnumFacing.WEST, EnumFacing.EAST, EnumFacing.DOWN, EnumFacing.UP}, 0.8F, true, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.WEST}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.FLIP_WEST, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.WEST, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.WEST}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.EAST}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.FLIP_EAST, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.EAST, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.EAST}),
WEST(new EnumFacing[]{EnumFacing.UP, EnumFacing.DOWN, EnumFacing.NORTH, EnumFacing.SOUTH}, 0.6F, true, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.SOUTH, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.SOUTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.NORTH, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.NORTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.NORTH, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.NORTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.SOUTH, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.SOUTH}),
EAST(new EnumFacing[]{EnumFacing.DOWN, EnumFacing.UP, EnumFacing.NORTH, EnumFacing.SOUTH}, 0.6F, true, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.SOUTH, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.SOUTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.NORTH, BlockModelRenderer.Orientation.FLIP_DOWN, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.DOWN, BlockModelRenderer.Orientation.NORTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.NORTH, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.FLIP_NORTH, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.NORTH}, new BlockModelRenderer.Orientation[]{BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.SOUTH, BlockModelRenderer.Orientation.FLIP_UP, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.FLIP_SOUTH, BlockModelRenderer.Orientation.UP, BlockModelRenderer.Orientation.SOUTH});
private final EnumFacing[] corners;
private final float shadeWeight;
private final boolean doNonCubicWeight;
private final BlockModelRenderer.Orientation[] vert0Weights;
private final BlockModelRenderer.Orientation[] vert1Weights;
private final BlockModelRenderer.Orientation[] vert2Weights;
private final BlockModelRenderer.Orientation[] vert3Weights;
private static final BlockModelRenderer.EnumNeighborInfo[] VALUES = new BlockModelRenderer.EnumNeighborInfo[6];
private EnumNeighborInfo(EnumFacing[] p_i46236_3_, float p_i46236_4_, boolean p_i46236_5_, BlockModelRenderer.Orientation[] p_i46236_6_, BlockModelRenderer.Orientation[] p_i46236_7_, BlockModelRenderer.Orientation[] p_i46236_8_, BlockModelRenderer.Orientation[] p_i46236_9_)
{
this.corners = p_i46236_3_;
this.shadeWeight = p_i46236_4_;
this.doNonCubicWeight = p_i46236_5_;
this.vert0Weights = p_i46236_6_;
this.vert1Weights = p_i46236_7_;
this.vert2Weights = p_i46236_8_;
this.vert3Weights = p_i46236_9_;
}
public static BlockModelRenderer.EnumNeighborInfo getNeighbourInfo(EnumFacing p_178273_0_)
{
return VALUES[p_178273_0_.getIndex()];
}
static
{
VALUES[EnumFacing.DOWN.getIndex()] = DOWN;
VALUES[EnumFacing.UP.getIndex()] = UP;
VALUES[EnumFacing.NORTH.getIndex()] = NORTH;
VALUES[EnumFacing.SOUTH.getIndex()] = SOUTH;
VALUES[EnumFacing.WEST.getIndex()] = WEST;
VALUES[EnumFacing.EAST.getIndex()] = EAST;
}
}
@SideOnly(Side.CLIENT)
public static enum Orientation
{
DOWN(EnumFacing.DOWN, false),
UP(EnumFacing.UP, false),
NORTH(EnumFacing.NORTH, false),
SOUTH(EnumFacing.SOUTH, false),
WEST(EnumFacing.WEST, false),
EAST(EnumFacing.EAST, false),
FLIP_DOWN(EnumFacing.DOWN, true),
FLIP_UP(EnumFacing.UP, true),
FLIP_NORTH(EnumFacing.NORTH, true),
FLIP_SOUTH(EnumFacing.SOUTH, true),
FLIP_WEST(EnumFacing.WEST, true),
FLIP_EAST(EnumFacing.EAST, true);
private final int shape;
private Orientation(EnumFacing p_i46233_3_, boolean p_i46233_4_)
{
this.shape = p_i46233_3_.getIndex() + (p_i46233_4_ ? EnumFacing.values().length : 0);
}
}
@SideOnly(Side.CLIENT)
static enum VertexTranslations
{
DOWN(0, 1, 2, 3),
UP(2, 3, 0, 1),
NORTH(3, 0, 1, 2),
SOUTH(0, 1, 2, 3),
WEST(3, 0, 1, 2),
EAST(1, 2, 3, 0);
private final int vert0;
private final int vert1;
private final int vert2;
private final int vert3;
private static final BlockModelRenderer.VertexTranslations[] VALUES = new BlockModelRenderer.VertexTranslations[6];
private VertexTranslations(int p_i46234_3_, int p_i46234_4_, int p_i46234_5_, int p_i46234_6_)
{
this.vert0 = p_i46234_3_;
this.vert1 = p_i46234_4_;
this.vert2 = p_i46234_5_;
this.vert3 = p_i46234_6_;
}
public static BlockModelRenderer.VertexTranslations getVertexTranslations(EnumFacing p_178184_0_)
{
return VALUES[p_178184_0_.getIndex()];
}
static
{
VALUES[EnumFacing.DOWN.getIndex()] = DOWN;
VALUES[EnumFacing.UP.getIndex()] = UP;
VALUES[EnumFacing.NORTH.getIndex()] = NORTH;
VALUES[EnumFacing.SOUTH.getIndex()] = SOUTH;
VALUES[EnumFacing.WEST.getIndex()] = WEST;
VALUES[EnumFacing.EAST.getIndex()] = EAST;
}
}
}

View File

@@ -0,0 +1,396 @@
package net.minecraft.client.renderer;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCactus;
import net.minecraft.block.BlockColored;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockDispenser;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.BlockDropper;
import net.minecraft.block.BlockFenceGate;
import net.minecraft.block.BlockFire;
import net.minecraft.block.BlockFlowerPot;
import net.minecraft.block.BlockHopper;
import net.minecraft.block.BlockJukebox;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockNewLeaf;
import net.minecraft.block.BlockNewLog;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.BlockOldLog;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.BlockPrismarine;
import net.minecraft.block.BlockQuartz;
import net.minecraft.block.BlockRedSandstone;
import net.minecraft.block.BlockRedstoneWire;
import net.minecraft.block.BlockReed;
import net.minecraft.block.BlockSand;
import net.minecraft.block.BlockSandStone;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.BlockSilverfish;
import net.minecraft.block.BlockStem;
import net.minecraft.block.BlockStone;
import net.minecraft.block.BlockStoneBrick;
import net.minecraft.block.BlockStoneSlab;
import net.minecraft.block.BlockStoneSlabNew;
import net.minecraft.block.BlockTNT;
import net.minecraft.block.BlockTallGrass;
import net.minecraft.block.BlockTripWire;
import net.minecraft.block.BlockWall;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelManager;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.BlockStateMapper;
import net.minecraft.client.renderer.block.statemap.IStateMapper;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BlockModelShapes
{
private final Map<IBlockState, IBakedModel> bakedModelStore = Maps.<IBlockState, IBakedModel>newIdentityHashMap();
private final BlockStateMapper blockStateMapper = new BlockStateMapper();
private final ModelManager modelManager;
public BlockModelShapes(ModelManager manager)
{
this.modelManager = manager;
this.registerAllBlocks();
}
public BlockStateMapper getBlockStateMapper()
{
return this.blockStateMapper;
}
public TextureAtlasSprite getTexture(IBlockState state)
{
Block block = state.getBlock();
IBakedModel ibakedmodel = this.getModelForState(state);
if (ibakedmodel == null || ibakedmodel == this.modelManager.getMissingModel())
{
if (block == Blocks.WALL_SIGN || block == Blocks.STANDING_SIGN || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST || block == Blocks.STANDING_BANNER || block == Blocks.WALL_BANNER || block == Blocks.BED)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/planks_oak");
}
if (block == Blocks.ENDER_CHEST)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/obsidian");
}
if (block == Blocks.FLOWING_LAVA || block == Blocks.LAVA)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/lava_still");
}
if (block == Blocks.FLOWING_WATER || block == Blocks.WATER)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/water_still");
}
if (block == Blocks.SKULL)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/soul_sand");
}
if (block == Blocks.BARRIER)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:items/barrier");
}
if (block == Blocks.STRUCTURE_VOID)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:items/structure_void");
}
if (block == Blocks.WHITE_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_white");
}
if (block == Blocks.ORANGE_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_orange");
}
if (block == Blocks.MAGENTA_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_magenta");
}
if (block == Blocks.LIGHT_BLUE_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_light_blue");
}
if (block == Blocks.YELLOW_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_yellow");
}
if (block == Blocks.LIME_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_lime");
}
if (block == Blocks.PINK_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_pink");
}
if (block == Blocks.GRAY_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_gray");
}
if (block == Blocks.SILVER_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_silver");
}
if (block == Blocks.CYAN_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_cyan");
}
if (block == Blocks.PURPLE_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_purple");
}
if (block == Blocks.BLUE_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_blue");
}
if (block == Blocks.BROWN_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_brown");
}
if (block == Blocks.GREEN_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_green");
}
if (block == Blocks.RED_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_red");
}
if (block == Blocks.BLACK_SHULKER_BOX)
{
return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/shulker_top_black");
}
}
if (ibakedmodel == null)
{
ibakedmodel = this.modelManager.getMissingModel();
}
return ibakedmodel.getParticleTexture();
}
public IBakedModel getModelForState(IBlockState state)
{
IBakedModel ibakedmodel = this.bakedModelStore.get(state);
if (ibakedmodel == null)
{
ibakedmodel = this.modelManager.getMissingModel();
}
return ibakedmodel;
}
public ModelManager getModelManager()
{
return this.modelManager;
}
public void reloadModels()
{
this.bakedModelStore.clear();
for (Entry<IBlockState, ModelResourceLocation> entry : this.blockStateMapper.putAllStateModelLocations().entrySet())
{
this.bakedModelStore.put(entry.getKey(), this.modelManager.getModel(entry.getValue()));
}
}
public void registerBlockWithStateMapper(Block assoc, IStateMapper stateMapper)
{
this.blockStateMapper.registerBlockStateMapper(assoc, stateMapper);
}
public void registerBuiltInBlocks(Block... builtIns)
{
this.blockStateMapper.registerBuiltInBlocks(builtIns);
}
private void registerAllBlocks()
{
this.registerBuiltInBlocks(Blocks.AIR, Blocks.FLOWING_WATER, Blocks.WATER, Blocks.FLOWING_LAVA, Blocks.LAVA, Blocks.PISTON_EXTENSION, Blocks.CHEST, Blocks.ENDER_CHEST, Blocks.TRAPPED_CHEST, Blocks.STANDING_SIGN, Blocks.SKULL, Blocks.END_PORTAL, Blocks.BARRIER, Blocks.WALL_SIGN, Blocks.WALL_BANNER, Blocks.STANDING_BANNER, Blocks.END_GATEWAY, Blocks.STRUCTURE_VOID, Blocks.WHITE_SHULKER_BOX, Blocks.ORANGE_SHULKER_BOX, Blocks.MAGENTA_SHULKER_BOX, Blocks.LIGHT_BLUE_SHULKER_BOX, Blocks.YELLOW_SHULKER_BOX, Blocks.LIME_SHULKER_BOX, Blocks.PINK_SHULKER_BOX, Blocks.GRAY_SHULKER_BOX, Blocks.SILVER_SHULKER_BOX, Blocks.CYAN_SHULKER_BOX, Blocks.PURPLE_SHULKER_BOX, Blocks.BLUE_SHULKER_BOX, Blocks.BROWN_SHULKER_BOX, Blocks.GREEN_SHULKER_BOX, Blocks.RED_SHULKER_BOX, Blocks.BLACK_SHULKER_BOX, Blocks.BED);
this.registerBlockWithStateMapper(Blocks.STONE, (new StateMap.Builder()).withName(BlockStone.VARIANT).build());
this.registerBlockWithStateMapper(Blocks.PRISMARINE, (new StateMap.Builder()).withName(BlockPrismarine.VARIANT).build());
this.registerBlockWithStateMapper(Blocks.LEAVES, (new StateMap.Builder()).withName(BlockOldLeaf.VARIANT).withSuffix("_leaves").ignore(BlockLeaves.CHECK_DECAY, BlockLeaves.DECAYABLE).build());
this.registerBlockWithStateMapper(Blocks.LEAVES2, (new StateMap.Builder()).withName(BlockNewLeaf.VARIANT).withSuffix("_leaves").ignore(BlockLeaves.CHECK_DECAY, BlockLeaves.DECAYABLE).build());
this.registerBlockWithStateMapper(Blocks.CACTUS, (new StateMap.Builder()).ignore(BlockCactus.AGE).build());
this.registerBlockWithStateMapper(Blocks.REEDS, (new StateMap.Builder()).ignore(BlockReed.AGE).build());
this.registerBlockWithStateMapper(Blocks.JUKEBOX, (new StateMap.Builder()).ignore(BlockJukebox.HAS_RECORD).build());
this.registerBlockWithStateMapper(Blocks.COBBLESTONE_WALL, (new StateMap.Builder()).withName(BlockWall.VARIANT).withSuffix("_wall").build());
this.registerBlockWithStateMapper(Blocks.DOUBLE_PLANT, (new StateMap.Builder()).withName(BlockDoublePlant.VARIANT).ignore(BlockDoublePlant.FACING).build());
this.registerBlockWithStateMapper(Blocks.OAK_FENCE_GATE, (new StateMap.Builder()).ignore(BlockFenceGate.POWERED).build());
this.registerBlockWithStateMapper(Blocks.SPRUCE_FENCE_GATE, (new StateMap.Builder()).ignore(BlockFenceGate.POWERED).build());
this.registerBlockWithStateMapper(Blocks.BIRCH_FENCE_GATE, (new StateMap.Builder()).ignore(BlockFenceGate.POWERED).build());
this.registerBlockWithStateMapper(Blocks.JUNGLE_FENCE_GATE, (new StateMap.Builder()).ignore(BlockFenceGate.POWERED).build());
this.registerBlockWithStateMapper(Blocks.DARK_OAK_FENCE_GATE, (new StateMap.Builder()).ignore(BlockFenceGate.POWERED).build());
this.registerBlockWithStateMapper(Blocks.ACACIA_FENCE_GATE, (new StateMap.Builder()).ignore(BlockFenceGate.POWERED).build());
this.registerBlockWithStateMapper(Blocks.TRIPWIRE, (new StateMap.Builder()).ignore(BlockTripWire.DISARMED, BlockTripWire.POWERED).build());
this.registerBlockWithStateMapper(Blocks.DOUBLE_WOODEN_SLAB, (new StateMap.Builder()).withName(BlockPlanks.VARIANT).withSuffix("_double_slab").build());
this.registerBlockWithStateMapper(Blocks.WOODEN_SLAB, (new StateMap.Builder()).withName(BlockPlanks.VARIANT).withSuffix("_slab").build());
this.registerBlockWithStateMapper(Blocks.TNT, (new StateMap.Builder()).ignore(BlockTNT.EXPLODE).build());
this.registerBlockWithStateMapper(Blocks.FIRE, (new StateMap.Builder()).ignore(BlockFire.AGE).build());
this.registerBlockWithStateMapper(Blocks.REDSTONE_WIRE, (new StateMap.Builder()).ignore(BlockRedstoneWire.POWER).build());
this.registerBlockWithStateMapper(Blocks.OAK_DOOR, (new StateMap.Builder()).ignore(BlockDoor.POWERED).build());
this.registerBlockWithStateMapper(Blocks.SPRUCE_DOOR, (new StateMap.Builder()).ignore(BlockDoor.POWERED).build());
this.registerBlockWithStateMapper(Blocks.BIRCH_DOOR, (new StateMap.Builder()).ignore(BlockDoor.POWERED).build());
this.registerBlockWithStateMapper(Blocks.JUNGLE_DOOR, (new StateMap.Builder()).ignore(BlockDoor.POWERED).build());
this.registerBlockWithStateMapper(Blocks.ACACIA_DOOR, (new StateMap.Builder()).ignore(BlockDoor.POWERED).build());
this.registerBlockWithStateMapper(Blocks.DARK_OAK_DOOR, (new StateMap.Builder()).ignore(BlockDoor.POWERED).build());
this.registerBlockWithStateMapper(Blocks.IRON_DOOR, (new StateMap.Builder()).ignore(BlockDoor.POWERED).build());
this.registerBlockWithStateMapper(Blocks.WOOL, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_wool").build());
this.registerBlockWithStateMapper(Blocks.CARPET, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_carpet").build());
this.registerBlockWithStateMapper(Blocks.STAINED_HARDENED_CLAY, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_stained_hardened_clay").build());
this.registerBlockWithStateMapper(Blocks.STAINED_GLASS_PANE, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_stained_glass_pane").build());
this.registerBlockWithStateMapper(Blocks.STAINED_GLASS, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_stained_glass").build());
this.registerBlockWithStateMapper(Blocks.SANDSTONE, (new StateMap.Builder()).withName(BlockSandStone.TYPE).build());
this.registerBlockWithStateMapper(Blocks.RED_SANDSTONE, (new StateMap.Builder()).withName(BlockRedSandstone.TYPE).build());
this.registerBlockWithStateMapper(Blocks.TALLGRASS, (new StateMap.Builder()).withName(BlockTallGrass.TYPE).build());
this.registerBlockWithStateMapper(Blocks.YELLOW_FLOWER, (new StateMap.Builder()).withName(Blocks.YELLOW_FLOWER.getTypeProperty()).build());
this.registerBlockWithStateMapper(Blocks.RED_FLOWER, (new StateMap.Builder()).withName(Blocks.RED_FLOWER.getTypeProperty()).build());
this.registerBlockWithStateMapper(Blocks.STONE_SLAB, (new StateMap.Builder()).withName(BlockStoneSlab.VARIANT).withSuffix("_slab").build());
this.registerBlockWithStateMapper(Blocks.STONE_SLAB2, (new StateMap.Builder()).withName(BlockStoneSlabNew.VARIANT).withSuffix("_slab").build());
this.registerBlockWithStateMapper(Blocks.MONSTER_EGG, (new StateMap.Builder()).withName(BlockSilverfish.VARIANT).withSuffix("_monster_egg").build());
this.registerBlockWithStateMapper(Blocks.STONEBRICK, (new StateMap.Builder()).withName(BlockStoneBrick.VARIANT).build());
this.registerBlockWithStateMapper(Blocks.DISPENSER, (new StateMap.Builder()).ignore(BlockDispenser.TRIGGERED).build());
this.registerBlockWithStateMapper(Blocks.DROPPER, (new StateMap.Builder()).ignore(BlockDropper.TRIGGERED).build());
this.registerBlockWithStateMapper(Blocks.LOG, (new StateMap.Builder()).withName(BlockOldLog.VARIANT).withSuffix("_log").build());
this.registerBlockWithStateMapper(Blocks.LOG2, (new StateMap.Builder()).withName(BlockNewLog.VARIANT).withSuffix("_log").build());
this.registerBlockWithStateMapper(Blocks.PLANKS, (new StateMap.Builder()).withName(BlockPlanks.VARIANT).withSuffix("_planks").build());
this.registerBlockWithStateMapper(Blocks.SAPLING, (new StateMap.Builder()).withName(BlockSapling.TYPE).withSuffix("_sapling").build());
this.registerBlockWithStateMapper(Blocks.SAND, (new StateMap.Builder()).withName(BlockSand.VARIANT).build());
this.registerBlockWithStateMapper(Blocks.HOPPER, (new StateMap.Builder()).ignore(BlockHopper.ENABLED).build());
this.registerBlockWithStateMapper(Blocks.FLOWER_POT, (new StateMap.Builder()).ignore(BlockFlowerPot.LEGACY_DATA).build());
this.registerBlockWithStateMapper(Blocks.CONCRETE, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_concrete").build());
this.registerBlockWithStateMapper(Blocks.CONCRETE_POWDER, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_concrete_powder").build());
this.registerBlockWithStateMapper(Blocks.QUARTZ_BLOCK, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
BlockQuartz.EnumType blockquartz$enumtype = (BlockQuartz.EnumType)state.getValue(BlockQuartz.VARIANT);
switch (blockquartz$enumtype)
{
case DEFAULT:
default:
return new ModelResourceLocation("quartz_block", "normal");
case CHISELED:
return new ModelResourceLocation("chiseled_quartz_block", "normal");
case LINES_Y:
return new ModelResourceLocation("quartz_column", "axis=y");
case LINES_X:
return new ModelResourceLocation("quartz_column", "axis=x");
case LINES_Z:
return new ModelResourceLocation("quartz_column", "axis=z");
}
}
});
this.registerBlockWithStateMapper(Blocks.DEADBUSH, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
return new ModelResourceLocation("dead_bush", "normal");
}
});
this.registerBlockWithStateMapper(Blocks.PUMPKIN_STEM, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
Map < IProperty<?>, Comparable<? >> map = Maps. < IProperty<?>, Comparable<? >> newLinkedHashMap(state.getProperties());
if (state.getValue(BlockStem.FACING) != EnumFacing.UP)
{
map.remove(BlockStem.AGE);
}
return new ModelResourceLocation(Block.REGISTRY.getNameForObject(state.getBlock()), this.getPropertyString(map));
}
});
this.registerBlockWithStateMapper(Blocks.MELON_STEM, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
Map < IProperty<?>, Comparable<? >> map = Maps. < IProperty<?>, Comparable<? >> newLinkedHashMap(state.getProperties());
if (state.getValue(BlockStem.FACING) != EnumFacing.UP)
{
map.remove(BlockStem.AGE);
}
return new ModelResourceLocation(Block.REGISTRY.getNameForObject(state.getBlock()), this.getPropertyString(map));
}
});
this.registerBlockWithStateMapper(Blocks.DIRT, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
Map < IProperty<?>, Comparable<? >> map = Maps. < IProperty<?>, Comparable<? >> newLinkedHashMap(state.getProperties());
String s = BlockDirt.VARIANT.getName((BlockDirt.DirtType)map.remove(BlockDirt.VARIANT));
if (BlockDirt.DirtType.PODZOL != state.getValue(BlockDirt.VARIANT))
{
map.remove(BlockDirt.SNOWY);
}
return new ModelResourceLocation(s, this.getPropertyString(map));
}
});
this.registerBlockWithStateMapper(Blocks.DOUBLE_STONE_SLAB, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
Map < IProperty<?>, Comparable<? >> map = Maps. < IProperty<?>, Comparable<? >> newLinkedHashMap(state.getProperties());
String s = BlockStoneSlab.VARIANT.getName((BlockStoneSlab.EnumType)map.remove(BlockStoneSlab.VARIANT));
map.remove(BlockStoneSlab.SEAMLESS);
String s1 = ((Boolean)state.getValue(BlockStoneSlab.SEAMLESS)).booleanValue() ? "all" : "normal";
return new ModelResourceLocation(s + "_double_slab", s1);
}
});
this.registerBlockWithStateMapper(Blocks.DOUBLE_STONE_SLAB2, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
Map < IProperty<?>, Comparable<? >> map = Maps. < IProperty<?>, Comparable<? >> newLinkedHashMap(state.getProperties());
String s = BlockStoneSlabNew.VARIANT.getName((BlockStoneSlabNew.EnumType)map.remove(BlockStoneSlabNew.VARIANT));
map.remove(BlockStoneSlab.SEAMLESS);
String s1 = ((Boolean)state.getValue(BlockStoneSlabNew.SEAMLESS)).booleanValue() ? "all" : "normal";
return new ModelResourceLocation(s + "_double_slab", s1);
}
});
net.minecraftforge.client.model.ModelLoader.onRegisterAllBlocks(this);
}
}

View File

@@ -0,0 +1,133 @@
package net.minecraft.client.renderer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.SimpleBakedModel;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.ReportedException;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.WorldType;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BlockRendererDispatcher implements IResourceManagerReloadListener
{
private final BlockModelShapes blockModelShapes;
private final BlockModelRenderer blockModelRenderer;
private final ChestRenderer chestRenderer = new ChestRenderer();
private final BlockFluidRenderer fluidRenderer;
public BlockRendererDispatcher(BlockModelShapes p_i46577_1_, BlockColors p_i46577_2_)
{
this.blockModelShapes = p_i46577_1_;
this.blockModelRenderer = new net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer(p_i46577_2_);
this.fluidRenderer = new BlockFluidRenderer(p_i46577_2_);
}
public BlockModelShapes getBlockModelShapes()
{
return this.blockModelShapes;
}
public void renderBlockDamage(IBlockState state, BlockPos pos, TextureAtlasSprite texture, IBlockAccess blockAccess)
{
if (state.getRenderType() == EnumBlockRenderType.MODEL)
{
state = state.getActualState(blockAccess, pos);
IBakedModel ibakedmodel = this.blockModelShapes.getModelForState(state);
IBakedModel ibakedmodel1 = net.minecraftforge.client.ForgeHooksClient.getDamageModel(ibakedmodel, texture, state, blockAccess, pos);
this.blockModelRenderer.renderModel(blockAccess, ibakedmodel1, state, pos, Tessellator.getInstance().getBuffer(), true);
}
}
public boolean renderBlock(IBlockState state, BlockPos pos, IBlockAccess blockAccess, BufferBuilder bufferBuilderIn)
{
try
{
EnumBlockRenderType enumblockrendertype = state.getRenderType();
if (enumblockrendertype == EnumBlockRenderType.INVISIBLE)
{
return false;
}
else
{
if (blockAccess.getWorldType() != WorldType.DEBUG_ALL_BLOCK_STATES)
{
try
{
state = state.getActualState(blockAccess, pos);
}
catch (Exception var8)
{
;
}
}
switch (enumblockrendertype)
{
case MODEL:
IBakedModel model = this.getModelForState(state);
state = state.getBlock().getExtendedState(state, blockAccess, pos);
return this.blockModelRenderer.renderModel(blockAccess, model, state, pos, bufferBuilderIn, true);
case ENTITYBLOCK_ANIMATED:
return false;
case LIQUID:
return this.fluidRenderer.renderFluid(blockAccess, state, pos, bufferBuilderIn);
default:
return false;
}
}
}
catch (Throwable throwable)
{
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Tesselating block in world");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being tesselated");
CrashReportCategory.addBlockInfo(crashreportcategory, pos, state.getBlock(), state.getBlock().getMetaFromState(state));
throw new ReportedException(crashreport);
}
}
public BlockModelRenderer getBlockModelRenderer()
{
return this.blockModelRenderer;
}
public IBakedModel getModelForState(IBlockState state)
{
return this.blockModelShapes.getModelForState(state);
}
@SuppressWarnings("incomplete-switch")
public void renderBlockBrightness(IBlockState state, float brightness)
{
EnumBlockRenderType enumblockrendertype = state.getRenderType();
if (enumblockrendertype != EnumBlockRenderType.INVISIBLE)
{
switch (enumblockrendertype)
{
case MODEL:
IBakedModel ibakedmodel = this.getModelForState(state);
this.blockModelRenderer.renderModelBrightness(ibakedmodel, state, brightness, true);
break;
case ENTITYBLOCK_ANIMATED:
this.chestRenderer.renderChestBrightness(state.getBlock(), brightness);
case LIQUID:
}
}
}
public void onResourceManagerReload(IResourceManager resourceManager)
{
this.fluidRenderer.initAtlasSprites();
}
}

View File

@@ -0,0 +1,648 @@
package net.minecraft.client.renderer;
import com.google.common.primitives.Floats;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class BufferBuilder
{
private static final Logger LOGGER = LogManager.getLogger();
private ByteBuffer byteBuffer;
private IntBuffer rawIntBuffer;
private ShortBuffer rawShortBuffer;
private FloatBuffer rawFloatBuffer;
private int vertexCount;
private VertexFormatElement vertexFormatElement;
private int vertexFormatIndex;
/** None */
private boolean noColor;
private int drawMode;
private double xOffset;
private double yOffset;
private double zOffset;
private VertexFormat vertexFormat;
private boolean isDrawing;
public BufferBuilder(int bufferSizeIn)
{
this.byteBuffer = GLAllocation.createDirectByteBuffer(bufferSizeIn * 4);
this.rawIntBuffer = this.byteBuffer.asIntBuffer();
this.rawShortBuffer = this.byteBuffer.asShortBuffer();
this.rawFloatBuffer = this.byteBuffer.asFloatBuffer();
}
private void growBuffer(int p_181670_1_)
{
if (MathHelper.roundUp(p_181670_1_, 4) / 4 > this.rawIntBuffer.remaining() || this.vertexCount * this.vertexFormat.getNextOffset() + p_181670_1_ > this.byteBuffer.capacity())
{
int i = this.byteBuffer.capacity();
int j = i + MathHelper.roundUp(p_181670_1_, 2097152);
LOGGER.debug("Needed to grow BufferBuilder buffer: Old size {} bytes, new size {} bytes.", Integer.valueOf(i), Integer.valueOf(j));
int k = this.rawIntBuffer.position();
ByteBuffer bytebuffer = GLAllocation.createDirectByteBuffer(j);
this.byteBuffer.position(0);
bytebuffer.put(this.byteBuffer);
bytebuffer.rewind();
this.byteBuffer = bytebuffer;
this.rawFloatBuffer = this.byteBuffer.asFloatBuffer().asReadOnlyBuffer();
this.rawIntBuffer = this.byteBuffer.asIntBuffer();
this.rawIntBuffer.position(k);
this.rawShortBuffer = this.byteBuffer.asShortBuffer();
this.rawShortBuffer.position(k << 1);
}
}
public void sortVertexData(float p_181674_1_, float p_181674_2_, float p_181674_3_)
{
int i = this.vertexCount / 4;
final float[] afloat = new float[i];
for (int j = 0; j < i; ++j)
{
afloat[j] = getDistanceSq(this.rawFloatBuffer, (float)((double)p_181674_1_ + this.xOffset), (float)((double)p_181674_2_ + this.yOffset), (float)((double)p_181674_3_ + this.zOffset), this.vertexFormat.getIntegerSize(), j * this.vertexFormat.getNextOffset());
}
Integer[] ainteger = new Integer[i];
for (int k = 0; k < ainteger.length; ++k)
{
ainteger[k] = k;
}
Arrays.sort(ainteger, new Comparator<Integer>()
{
public int compare(Integer p_compare_1_, Integer p_compare_2_)
{
return Floats.compare(afloat[p_compare_2_.intValue()], afloat[p_compare_1_.intValue()]);
}
});
BitSet bitset = new BitSet();
int l = this.vertexFormat.getNextOffset();
int[] aint = new int[l];
for (int i1 = bitset.nextClearBit(0); i1 < ainteger.length; i1 = bitset.nextClearBit(i1 + 1))
{
int j1 = ainteger[i1].intValue();
if (j1 != i1)
{
this.rawIntBuffer.limit(j1 * l + l);
this.rawIntBuffer.position(j1 * l);
this.rawIntBuffer.get(aint);
int k1 = j1;
for (int l1 = ainteger[j1].intValue(); k1 != i1; l1 = ainteger[l1].intValue())
{
this.rawIntBuffer.limit(l1 * l + l);
this.rawIntBuffer.position(l1 * l);
IntBuffer intbuffer = this.rawIntBuffer.slice();
this.rawIntBuffer.limit(k1 * l + l);
this.rawIntBuffer.position(k1 * l);
this.rawIntBuffer.put(intbuffer);
bitset.set(k1);
k1 = l1;
}
this.rawIntBuffer.limit(i1 * l + l);
this.rawIntBuffer.position(i1 * l);
this.rawIntBuffer.put(aint);
}
bitset.set(i1);
}
this.rawIntBuffer.limit(this.rawIntBuffer.capacity());
this.rawIntBuffer.position(this.getBufferSize());
}
public BufferBuilder.State getVertexState()
{
this.rawIntBuffer.rewind();
int i = this.getBufferSize();
this.rawIntBuffer.limit(i);
int[] aint = new int[i];
this.rawIntBuffer.get(aint);
this.rawIntBuffer.limit(this.rawIntBuffer.capacity());
this.rawIntBuffer.position(i);
return new BufferBuilder.State(aint, new VertexFormat(this.vertexFormat));
}
private int getBufferSize()
{
return this.vertexCount * this.vertexFormat.getIntegerSize();
}
private static float getDistanceSq(FloatBuffer p_181665_0_, float p_181665_1_, float p_181665_2_, float p_181665_3_, int p_181665_4_, int p_181665_5_)
{
float f = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 0 + 0);
float f1 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 0 + 1);
float f2 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 0 + 2);
float f3 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 1 + 0);
float f4 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 1 + 1);
float f5 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 1 + 2);
float f6 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 2 + 0);
float f7 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 2 + 1);
float f8 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 2 + 2);
float f9 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 3 + 0);
float f10 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 3 + 1);
float f11 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 3 + 2);
float f12 = (f + f3 + f6 + f9) * 0.25F - p_181665_1_;
float f13 = (f1 + f4 + f7 + f10) * 0.25F - p_181665_2_;
float f14 = (f2 + f5 + f8 + f11) * 0.25F - p_181665_3_;
return f12 * f12 + f13 * f13 + f14 * f14;
}
public void setVertexState(BufferBuilder.State state)
{
this.rawIntBuffer.clear();
this.growBuffer(state.getRawBuffer().length * 4);
this.rawIntBuffer.put(state.getRawBuffer());
this.vertexCount = state.getVertexCount();
this.vertexFormat = new VertexFormat(state.getVertexFormat());
}
public void reset()
{
this.vertexCount = 0;
this.vertexFormatElement = null;
this.vertexFormatIndex = 0;
}
public void begin(int glMode, VertexFormat format)
{
if (this.isDrawing)
{
throw new IllegalStateException("Already building!");
}
else
{
this.isDrawing = true;
this.reset();
this.drawMode = glMode;
this.vertexFormat = format;
this.vertexFormatElement = format.getElement(this.vertexFormatIndex);
this.noColor = false;
this.byteBuffer.limit(this.byteBuffer.capacity());
}
}
public BufferBuilder tex(double u, double v)
{
int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
switch (this.vertexFormatElement.getType())
{
case FLOAT:
this.byteBuffer.putFloat(i, (float)u);
this.byteBuffer.putFloat(i + 4, (float)v);
break;
case UINT:
case INT:
this.byteBuffer.putInt(i, (int)u);
this.byteBuffer.putInt(i + 4, (int)v);
break;
case USHORT:
case SHORT:
this.byteBuffer.putShort(i, (short)((int)v));
this.byteBuffer.putShort(i + 2, (short)((int)u));
break;
case UBYTE:
case BYTE:
this.byteBuffer.put(i, (byte)((int)v));
this.byteBuffer.put(i + 1, (byte)((int)u));
}
this.nextVertexFormatIndex();
return this;
}
public BufferBuilder lightmap(int p_187314_1_, int p_187314_2_)
{
int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
switch (this.vertexFormatElement.getType())
{
case FLOAT:
this.byteBuffer.putFloat(i, (float)p_187314_1_);
this.byteBuffer.putFloat(i + 4, (float)p_187314_2_);
break;
case UINT:
case INT:
this.byteBuffer.putInt(i, p_187314_1_);
this.byteBuffer.putInt(i + 4, p_187314_2_);
break;
case USHORT:
case SHORT:
this.byteBuffer.putShort(i, (short)p_187314_2_);
this.byteBuffer.putShort(i + 2, (short)p_187314_1_);
break;
case UBYTE:
case BYTE:
this.byteBuffer.put(i, (byte)p_187314_2_);
this.byteBuffer.put(i + 1, (byte)p_187314_1_);
}
this.nextVertexFormatIndex();
return this;
}
public void putBrightness4(int p_178962_1_, int p_178962_2_, int p_178962_3_, int p_178962_4_)
{
int i = (this.vertexCount - 4) * this.vertexFormat.getIntegerSize() + this.vertexFormat.getUvOffsetById(1) / 4;
int j = this.vertexFormat.getNextOffset() >> 2;
this.rawIntBuffer.put(i, p_178962_1_);
this.rawIntBuffer.put(i + j, p_178962_2_);
this.rawIntBuffer.put(i + j * 2, p_178962_3_);
this.rawIntBuffer.put(i + j * 3, p_178962_4_);
}
public void putPosition(double x, double y, double z)
{
int i = this.vertexFormat.getIntegerSize();
int j = (this.vertexCount - 4) * i;
for (int k = 0; k < 4; ++k)
{
int l = j + k * i;
int i1 = l + 1;
int j1 = i1 + 1;
this.rawIntBuffer.put(l, Float.floatToRawIntBits((float)(x + this.xOffset) + Float.intBitsToFloat(this.rawIntBuffer.get(l))));
this.rawIntBuffer.put(i1, Float.floatToRawIntBits((float)(y + this.yOffset) + Float.intBitsToFloat(this.rawIntBuffer.get(i1))));
this.rawIntBuffer.put(j1, Float.floatToRawIntBits((float)(z + this.zOffset) + Float.intBitsToFloat(this.rawIntBuffer.get(j1))));
}
}
/**
* Gets the position into the vertex data buffer at which the given vertex's color data can be found, in {@code
* int}s.
*/
public int getColorIndex(int vertexIndex)
{
return ((this.vertexCount - vertexIndex) * this.vertexFormat.getNextOffset() + this.vertexFormat.getColorOffset()) / 4;
}
/**
* Modify the color data of the given vertex with the given multipliers.
*/
public void putColorMultiplier(float red, float green, float blue, int vertexIndex)
{
int i = this.getColorIndex(vertexIndex);
int j = -1;
if (!this.noColor)
{
j = this.rawIntBuffer.get(i);
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN)
{
int k = (int)((float)(j & 255) * red);
int l = (int)((float)(j >> 8 & 255) * green);
int i1 = (int)((float)(j >> 16 & 255) * blue);
j = j & -16777216;
j = j | i1 << 16 | l << 8 | k;
}
else
{
int j1 = (int)((float)(j >> 24 & 255) * red);
int k1 = (int)((float)(j >> 16 & 255) * green);
int l1 = (int)((float)(j >> 8 & 255) * blue);
j = j & 255;
j = j | j1 << 24 | k1 << 16 | l1 << 8;
}
}
this.rawIntBuffer.put(i, j);
}
private void putColor(int argb, int vertexIndex)
{
int i = this.getColorIndex(vertexIndex);
int j = argb >> 16 & 255;
int k = argb >> 8 & 255;
int l = argb & 255;
this.putColorRGBA(i, j, k, l);
}
public void putColorRGB_F(float red, float green, float blue, int vertexIndex)
{
int i = this.getColorIndex(vertexIndex);
int j = MathHelper.clamp((int)(red * 255.0F), 0, 255);
int k = MathHelper.clamp((int)(green * 255.0F), 0, 255);
int l = MathHelper.clamp((int)(blue * 255.0F), 0, 255);
this.putColorRGBA(i, j, k, l);
}
/**
* Write the given color data of 4 bytes at the given index into the vertex data buffer, accounting for system
* endianness.
*/
public void putColorRGBA(int index, int red, int green, int blue)
{
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN)
{
this.rawIntBuffer.put(index, -16777216 | blue << 16 | green << 8 | red);
}
else
{
this.rawIntBuffer.put(index, red << 24 | green << 16 | blue << 8 | 255);
}
}
/**
* Disables color processing.
*/
public void noColor()
{
this.noColor = true;
}
public BufferBuilder color(float red, float green, float blue, float alpha)
{
return this.color((int)(red * 255.0F), (int)(green * 255.0F), (int)(blue * 255.0F), (int)(alpha * 255.0F));
}
public BufferBuilder color(int red, int green, int blue, int alpha)
{
if (this.noColor)
{
return this;
}
else
{
int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
switch (this.vertexFormatElement.getType())
{
case FLOAT:
this.byteBuffer.putFloat(i, (float)red / 255.0F);
this.byteBuffer.putFloat(i + 4, (float)green / 255.0F);
this.byteBuffer.putFloat(i + 8, (float)blue / 255.0F);
this.byteBuffer.putFloat(i + 12, (float)alpha / 255.0F);
break;
case UINT:
case INT:
this.byteBuffer.putFloat(i, (float)red);
this.byteBuffer.putFloat(i + 4, (float)green);
this.byteBuffer.putFloat(i + 8, (float)blue);
this.byteBuffer.putFloat(i + 12, (float)alpha);
break;
case USHORT:
case SHORT:
this.byteBuffer.putShort(i, (short)red);
this.byteBuffer.putShort(i + 2, (short)green);
this.byteBuffer.putShort(i + 4, (short)blue);
this.byteBuffer.putShort(i + 6, (short)alpha);
break;
case UBYTE:
case BYTE:
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN)
{
this.byteBuffer.put(i, (byte)red);
this.byteBuffer.put(i + 1, (byte)green);
this.byteBuffer.put(i + 2, (byte)blue);
this.byteBuffer.put(i + 3, (byte)alpha);
}
else
{
this.byteBuffer.put(i, (byte)alpha);
this.byteBuffer.put(i + 1, (byte)blue);
this.byteBuffer.put(i + 2, (byte)green);
this.byteBuffer.put(i + 3, (byte)red);
}
}
this.nextVertexFormatIndex();
return this;
}
}
public void addVertexData(int[] vertexData)
{
this.growBuffer(vertexData.length * 4 + this.vertexFormat.getNextOffset());//Forge, fix MC-122110
this.rawIntBuffer.position(this.getBufferSize());
this.rawIntBuffer.put(vertexData);
this.vertexCount += vertexData.length / this.vertexFormat.getIntegerSize();
}
public void endVertex()
{
++this.vertexCount;
this.growBuffer(this.vertexFormat.getNextOffset());
}
public BufferBuilder pos(double x, double y, double z)
{
int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
switch (this.vertexFormatElement.getType())
{
case FLOAT:
this.byteBuffer.putFloat(i, (float)(x + this.xOffset));
this.byteBuffer.putFloat(i + 4, (float)(y + this.yOffset));
this.byteBuffer.putFloat(i + 8, (float)(z + this.zOffset));
break;
case UINT:
case INT:
this.byteBuffer.putInt(i, Float.floatToRawIntBits((float)(x + this.xOffset)));
this.byteBuffer.putInt(i + 4, Float.floatToRawIntBits((float)(y + this.yOffset)));
this.byteBuffer.putInt(i + 8, Float.floatToRawIntBits((float)(z + this.zOffset)));
break;
case USHORT:
case SHORT:
this.byteBuffer.putShort(i, (short)((int)(x + this.xOffset)));
this.byteBuffer.putShort(i + 2, (short)((int)(y + this.yOffset)));
this.byteBuffer.putShort(i + 4, (short)((int)(z + this.zOffset)));
break;
case UBYTE:
case BYTE:
this.byteBuffer.put(i, (byte)((int)(x + this.xOffset)));
this.byteBuffer.put(i + 1, (byte)((int)(y + this.yOffset)));
this.byteBuffer.put(i + 2, (byte)((int)(z + this.zOffset)));
}
this.nextVertexFormatIndex();
return this;
}
public void putNormal(float x, float y, float z)
{
int i = (byte)((int)(x * 127.0F)) & 255;
int j = (byte)((int)(y * 127.0F)) & 255;
int k = (byte)((int)(z * 127.0F)) & 255;
int l = i | j << 8 | k << 16;
int i1 = this.vertexFormat.getNextOffset() >> 2;
int j1 = (this.vertexCount - 4) * i1 + this.vertexFormat.getNormalOffset() / 4;
this.rawIntBuffer.put(j1, l);
this.rawIntBuffer.put(j1 + i1, l);
this.rawIntBuffer.put(j1 + i1 * 2, l);
this.rawIntBuffer.put(j1 + i1 * 3, l);
}
private void nextVertexFormatIndex()
{
++this.vertexFormatIndex;
this.vertexFormatIndex %= this.vertexFormat.getElementCount();
this.vertexFormatElement = this.vertexFormat.getElement(this.vertexFormatIndex);
if (this.vertexFormatElement.getUsage() == VertexFormatElement.EnumUsage.PADDING)
{
this.nextVertexFormatIndex();
}
}
public BufferBuilder normal(float x, float y, float z)
{
int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
switch (this.vertexFormatElement.getType())
{
case FLOAT:
this.byteBuffer.putFloat(i, x);
this.byteBuffer.putFloat(i + 4, y);
this.byteBuffer.putFloat(i + 8, z);
break;
case UINT:
case INT:
this.byteBuffer.putInt(i, (int)x);
this.byteBuffer.putInt(i + 4, (int)y);
this.byteBuffer.putInt(i + 8, (int)z);
break;
case USHORT:
case SHORT:
this.byteBuffer.putShort(i, (short)((int)(x * 32767) & 65535));
this.byteBuffer.putShort(i + 2, (short)((int)(y * 32767) & 65535));
this.byteBuffer.putShort(i + 4, (short)((int)(z * 32767) & 65535));
break;
case UBYTE:
case BYTE:
this.byteBuffer.put(i, (byte)((int)(x * 127) & 255));
this.byteBuffer.put(i + 1, (byte)((int)(y * 127) & 255));
this.byteBuffer.put(i + 2, (byte)((int)(z * 127) & 255));
}
this.nextVertexFormatIndex();
return this;
}
public void setTranslation(double x, double y, double z)
{
this.xOffset = x;
this.yOffset = y;
this.zOffset = z;
}
public void finishDrawing()
{
if (!this.isDrawing)
{
throw new IllegalStateException("Not building!");
}
else
{
this.isDrawing = false;
this.byteBuffer.position(0);
this.byteBuffer.limit(this.getBufferSize() * 4);
}
}
public ByteBuffer getByteBuffer()
{
return this.byteBuffer;
}
public VertexFormat getVertexFormat()
{
return this.vertexFormat;
}
public int getVertexCount()
{
return this.vertexCount;
}
public int getDrawMode()
{
return this.drawMode;
}
public void putColor4(int argb)
{
for (int i = 0; i < 4; ++i)
{
this.putColor(argb, i + 1);
}
}
public void putColorRGB_F4(float red, float green, float blue)
{
for (int i = 0; i < 4; ++i)
{
this.putColorRGB_F(red, green, blue, i + 1);
}
}
@SideOnly(Side.CLIENT)
public class State
{
private final int[] stateRawBuffer;
private final VertexFormat stateVertexFormat;
public State(int[] buffer, VertexFormat format)
{
this.stateRawBuffer = buffer;
this.stateVertexFormat = format;
}
public int[] getRawBuffer()
{
return this.stateRawBuffer;
}
public int getVertexCount()
{
return this.stateRawBuffer.length / this.stateVertexFormat.getIntegerSize();
}
public VertexFormat getVertexFormat()
{
return this.stateVertexFormat;
}
}
//For some unknown reason Mojang changed the vanilla function to hardcode alpha as 255.... So lets re-add the parameter -.-
public void putColorRGBA(int index, int red, int green, int blue, int alpha)
{
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN)
this.rawIntBuffer.put(index, alpha << 24 | blue << 16 | green << 8 | red);
else
this.rawIntBuffer.put(index, red << 24 | green << 16 | blue << 8 | alpha);
}
public boolean isColorDisabled()
{
return this.noColor;
}
public void putBulkData(ByteBuffer buffer)
{
growBuffer(buffer.limit() + this.vertexFormat.getNextOffset());
this.byteBuffer.position(this.vertexCount * this.vertexFormat.getNextOffset());
this.byteBuffer.put(buffer);
this.vertexCount += buffer.limit() / this.vertexFormat.getNextOffset();
}
}

View File

@@ -0,0 +1,19 @@
package net.minecraft.client.renderer;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ChestRenderer
{
public void renderChestBrightness(Block blockIn, float color)
{
GlStateManager.color(color, color, color, 1.0F);
GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
ItemStack stack = new ItemStack(blockIn);
stack.getItem().getTileEntityItemStackRenderer().renderByItem(stack);
}
}

View File

@@ -0,0 +1,41 @@
package net.minecraft.client.renderer;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class ChunkRenderContainer
{
private double viewEntityX;
private double viewEntityY;
private double viewEntityZ;
protected List<RenderChunk> renderChunks = Lists.<RenderChunk>newArrayListWithCapacity(17424);
protected boolean initialized;
public void initialize(double viewEntityXIn, double viewEntityYIn, double viewEntityZIn)
{
this.initialized = true;
this.renderChunks.clear();
this.viewEntityX = viewEntityXIn;
this.viewEntityY = viewEntityYIn;
this.viewEntityZ = viewEntityZIn;
}
public void preRenderChunk(RenderChunk renderChunkIn)
{
BlockPos blockpos = renderChunkIn.getPosition();
GlStateManager.translate((float)((double)blockpos.getX() - this.viewEntityX), (float)((double)blockpos.getY() - this.viewEntityY), (float)((double)blockpos.getZ() - this.viewEntityZ));
}
public void addRenderChunk(RenderChunk renderChunkIn, BlockRenderLayer layer)
{
this.renderChunks.add(renderChunkIn);
}
public abstract void renderChunkLayer(BlockRenderLayer layer);
}

View File

@@ -0,0 +1,66 @@
package net.minecraft.client.renderer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class DestroyBlockProgress
{
/**
* entity ID of the player associated with this partially destroyed Block. Used to identify the Blocks in the client
* Renderer, max 1 per player on a server
*/
private final int miningPlayerEntId;
private final BlockPos position;
/** damage ranges from 1 to 10. -1 causes the client to delete the partial block renderer. */
private int partialBlockProgress;
/** keeps track of how many ticks this PartiallyDestroyedBlock already exists */
private int createdAtCloudUpdateTick;
public DestroyBlockProgress(int miningPlayerEntIdIn, BlockPos positionIn)
{
this.miningPlayerEntId = miningPlayerEntIdIn;
this.position = positionIn;
}
public BlockPos getPosition()
{
return this.position;
}
/**
* inserts damage value into this partially destroyed Block. -1 causes client renderer to delete it, otherwise
* ranges from 1 to 10
*/
public void setPartialBlockDamage(int damage)
{
if (damage > 10)
{
damage = 10;
}
this.partialBlockProgress = damage;
}
public int getPartialBlockDamage()
{
return this.partialBlockProgress;
}
/**
* saves the current Cloud update tick into the PartiallyDestroyedBlock
*/
public void setCloudUpdateTick(int createdAtCloudUpdateTickIn)
{
this.createdAtCloudUpdateTick = createdAtCloudUpdateTickIn;
}
/**
* retrieves the 'date' at which the PartiallyDestroyedBlock was created
*/
public int getCreationCloudUpdateTick()
{
return this.createdAtCloudUpdateTick;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
package net.minecraft.client.renderer;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public enum EnumFaceDirection
{
DOWN(new EnumFaceDirection.VertexInformation[]{new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX)}),
UP(new EnumFaceDirection.VertexInformation[]{new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.NORTH_INDEX)}),
NORTH(new EnumFaceDirection.VertexInformation[]{new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.NORTH_INDEX)}),
SOUTH(new EnumFaceDirection.VertexInformation[]{new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX)}),
WEST(new EnumFaceDirection.VertexInformation[]{new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.WEST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX)}),
EAST(new EnumFaceDirection.VertexInformation[]{new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.SOUTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.DOWN_INDEX, EnumFaceDirection.Constants.NORTH_INDEX), new EnumFaceDirection.VertexInformation(EnumFaceDirection.Constants.EAST_INDEX, EnumFaceDirection.Constants.UP_INDEX, EnumFaceDirection.Constants.NORTH_INDEX)});
private static final EnumFaceDirection[] FACINGS = new EnumFaceDirection[6];
private final EnumFaceDirection.VertexInformation[] vertexInfos;
public static EnumFaceDirection getFacing(EnumFacing facing)
{
return FACINGS[facing.getIndex()];
}
private EnumFaceDirection(EnumFaceDirection.VertexInformation[] vertexInfosIn)
{
this.vertexInfos = vertexInfosIn;
}
public EnumFaceDirection.VertexInformation getVertexInformation(int index)
{
return this.vertexInfos[index];
}
static
{
FACINGS[EnumFaceDirection.Constants.DOWN_INDEX] = DOWN;
FACINGS[EnumFaceDirection.Constants.UP_INDEX] = UP;
FACINGS[EnumFaceDirection.Constants.NORTH_INDEX] = NORTH;
FACINGS[EnumFaceDirection.Constants.SOUTH_INDEX] = SOUTH;
FACINGS[EnumFaceDirection.Constants.WEST_INDEX] = WEST;
FACINGS[EnumFaceDirection.Constants.EAST_INDEX] = EAST;
}
@SideOnly(Side.CLIENT)
public static final class Constants
{
public static final int SOUTH_INDEX = EnumFacing.SOUTH.getIndex();
public static final int UP_INDEX = EnumFacing.UP.getIndex();
public static final int EAST_INDEX = EnumFacing.EAST.getIndex();
public static final int NORTH_INDEX = EnumFacing.NORTH.getIndex();
public static final int DOWN_INDEX = EnumFacing.DOWN.getIndex();
public static final int WEST_INDEX = EnumFacing.WEST.getIndex();
}
@SideOnly(Side.CLIENT)
public static class VertexInformation
{
public final int xIndex;
public final int yIndex;
public final int zIndex;
private VertexInformation(int xIndexIn, int yIndexIn, int zIndexIn)
{
this.xIndex = xIndexIn;
this.yIndex = yIndexIn;
this.zIndex = zIndexIn;
}
}
}

View File

@@ -0,0 +1,74 @@
package net.minecraft.client.renderer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.glu.GLU;
@SideOnly(Side.CLIENT)
public class GLAllocation
{
/**
* Generates the specified number of display lists and returns the first index.
*/
public static synchronized int generateDisplayLists(int range)
{
int i = GlStateManager.glGenLists(range);
if (i == 0)
{
int j = GlStateManager.glGetError();
String s = "No error code reported";
if (j != 0)
{
s = GLU.gluErrorString(j);
}
throw new IllegalStateException("glGenLists returned an ID of 0 for a count of " + range + ", GL error (" + j + "): " + s);
}
else
{
return i;
}
}
public static synchronized void deleteDisplayLists(int list, int range)
{
GlStateManager.glDeleteLists(list, range);
}
public static synchronized void deleteDisplayLists(int list)
{
deleteDisplayLists(list, 1);
}
/**
* Creates and returns a direct byte buffer with the specified capacity. Applies native ordering to speed up access.
*/
public static synchronized ByteBuffer createDirectByteBuffer(int capacity)
{
return ByteBuffer.allocateDirect(capacity).order(ByteOrder.nativeOrder());
}
/**
* Creates and returns a direct int buffer with the specified capacity. Applies native ordering to speed up access.
*/
public static IntBuffer createDirectIntBuffer(int capacity)
{
return createDirectByteBuffer(capacity << 2).asIntBuffer();
}
/**
* Creates and returns a direct float buffer with the specified capacity. Applies native ordering to speed up
* access.
*/
public static FloatBuffer createDirectFloatBuffer(int capacity)
{
return createDirectByteBuffer(capacity << 2).asFloatBuffer();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
package net.minecraft.client.renderer;
import java.awt.image.BufferedImage;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IImageBuffer
{
BufferedImage parseUserSkin(BufferedImage image);
void skinAvailable();
}

View File

@@ -0,0 +1,109 @@
package net.minecraft.client.renderer;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
import javax.annotation.Nullable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ImageBufferDownload implements IImageBuffer
{
private int[] imageData;
private int imageWidth;
private int imageHeight;
@Nullable
public BufferedImage parseUserSkin(BufferedImage image)
{
if (image == null)
{
return null;
}
else
{
this.imageWidth = 64;
this.imageHeight = 64;
BufferedImage bufferedimage = new BufferedImage(this.imageWidth, this.imageHeight, 2);
Graphics graphics = bufferedimage.getGraphics();
graphics.drawImage(image, 0, 0, (ImageObserver)null);
boolean flag = image.getHeight() == 32;
if (flag)
{
graphics.setColor(new Color(0, 0, 0, 0));
graphics.fillRect(0, 32, 64, 32);
graphics.drawImage(bufferedimage, 24, 48, 20, 52, 4, 16, 8, 20, (ImageObserver)null);
graphics.drawImage(bufferedimage, 28, 48, 24, 52, 8, 16, 12, 20, (ImageObserver)null);
graphics.drawImage(bufferedimage, 20, 52, 16, 64, 8, 20, 12, 32, (ImageObserver)null);
graphics.drawImage(bufferedimage, 24, 52, 20, 64, 4, 20, 8, 32, (ImageObserver)null);
graphics.drawImage(bufferedimage, 28, 52, 24, 64, 0, 20, 4, 32, (ImageObserver)null);
graphics.drawImage(bufferedimage, 32, 52, 28, 64, 12, 20, 16, 32, (ImageObserver)null);
graphics.drawImage(bufferedimage, 40, 48, 36, 52, 44, 16, 48, 20, (ImageObserver)null);
graphics.drawImage(bufferedimage, 44, 48, 40, 52, 48, 16, 52, 20, (ImageObserver)null);
graphics.drawImage(bufferedimage, 36, 52, 32, 64, 48, 20, 52, 32, (ImageObserver)null);
graphics.drawImage(bufferedimage, 40, 52, 36, 64, 44, 20, 48, 32, (ImageObserver)null);
graphics.drawImage(bufferedimage, 44, 52, 40, 64, 40, 20, 44, 32, (ImageObserver)null);
graphics.drawImage(bufferedimage, 48, 52, 44, 64, 52, 20, 56, 32, (ImageObserver)null);
}
graphics.dispose();
this.imageData = ((DataBufferInt)bufferedimage.getRaster().getDataBuffer()).getData();
this.setAreaOpaque(0, 0, 32, 16);
if (flag)
{
this.setAreaTransparent(32, 0, 64, 32);
}
this.setAreaOpaque(0, 16, 64, 32);
this.setAreaOpaque(16, 48, 48, 64);
return bufferedimage;
}
}
public void skinAvailable()
{
}
private void setAreaTransparent(int x, int y, int width, int height)
{
for (int i = x; i < width; ++i)
{
for (int j = y; j < height; ++j)
{
int k = this.imageData[i + j * this.imageWidth];
if ((k >> 24 & 255) < 128)
{
return;
}
}
}
for (int l = x; l < width; ++l)
{
for (int i1 = y; i1 < height; ++i1)
{
this.imageData[l + i1 * this.imageWidth] &= 16777215;
}
}
}
/**
* Makes the given area of the image opaque
*/
private void setAreaOpaque(int x, int y, int width, int height)
{
for (int i = x; i < width; ++i)
{
for (int j = y; j < height; ++j)
{
this.imageData[i + j * this.imageWidth] |= -16777216;
}
}
}
}

View File

@@ -0,0 +1,126 @@
package net.minecraft.client.renderer;
import com.google.common.collect.Ordering;
import java.util.Collection;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.inventory.Container;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class InventoryEffectRenderer extends GuiContainer
{
/** True if there is some potion effect to display */
protected boolean hasActivePotionEffects;
public InventoryEffectRenderer(Container inventorySlotsIn)
{
super(inventorySlotsIn);
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
this.updateActivePotionEffects();
}
protected void updateActivePotionEffects()
{
boolean hasVisibleEffect = false;
for(PotionEffect potioneffect : this.mc.player.getActivePotionEffects()) {
Potion potion = potioneffect.getPotion();
if(potion.shouldRender(potioneffect)) { hasVisibleEffect = true; break; }
}
if (this.mc.player.getActivePotionEffects().isEmpty() || !hasVisibleEffect)
{
this.guiLeft = (this.width - this.xSize) / 2;
this.hasActivePotionEffects = false;
}
else
{
if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.PotionShiftEvent(this))) this.guiLeft = (this.width - this.xSize) / 2; else
this.guiLeft = 160 + (this.width - this.xSize - 200) / 2;
this.hasActivePotionEffects = true;
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
super.drawScreen(mouseX, mouseY, partialTicks);
if (this.hasActivePotionEffects)
{
this.drawActivePotionEffects();
}
}
/**
* Display the potion effects list
*/
private void drawActivePotionEffects()
{
int i = this.guiLeft - 124;
int j = this.guiTop;
int k = 166;
Collection<PotionEffect> collection = this.mc.player.getActivePotionEffects();
if (!collection.isEmpty())
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableLighting();
int l = 33;
if (collection.size() > 5)
{
l = 132 / (collection.size() - 1);
}
for (PotionEffect potioneffect : Ordering.natural().sortedCopy(collection))
{
Potion potion = potioneffect.getPotion();
if(!potion.shouldRender(potioneffect)) continue;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(INVENTORY_BACKGROUND);
this.drawTexturedModalRect(i, j, 0, 166, 140, 32);
if (potion.hasStatusIcon())
{
int i1 = potion.getStatusIconIndex();
this.drawTexturedModalRect(i + 6, j + 7, 0 + i1 % 8 * 18, 198 + i1 / 8 * 18, 18, 18);
}
potion.renderInventoryEffect(i, j, potioneffect, mc);
if (!potion.shouldRenderInvText(potioneffect)) { j += l; continue; }
String s1 = I18n.format(potion.getName());
if (potioneffect.getAmplifier() == 1)
{
s1 = s1 + " " + I18n.format("enchantment.level.2");
}
else if (potioneffect.getAmplifier() == 2)
{
s1 = s1 + " " + I18n.format("enchantment.level.3");
}
else if (potioneffect.getAmplifier() == 3)
{
s1 = s1 + " " + I18n.format("enchantment.level.4");
}
this.fontRenderer.drawStringWithShadow(s1, (float)(i + 10 + 18), (float)(j + 6), 16777215);
String s = Potion.getPotionDurationString(potioneffect, 1.0F);
this.fontRenderer.drawStringWithShadow(s, (float)(i + 10 + 18), (float)(j + 6 + 10), 8355711);
j += l;
}
}
}
}

View File

@@ -0,0 +1,12 @@
package net.minecraft.client.renderer;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface ItemMeshDefinition
{
ModelResourceLocation getModelLocation(ItemStack stack);
}

View File

@@ -0,0 +1,105 @@
package net.minecraft.client.renderer;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelManager;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ItemModelMesher
{
private final Map<Integer, ModelResourceLocation> simpleShapes = Maps.<Integer, ModelResourceLocation>newHashMap();
private final Map<Integer, IBakedModel> simpleShapesCache = Maps.<Integer, IBakedModel>newHashMap();
protected final Map<Item, ItemMeshDefinition> shapers = Maps.<Item, ItemMeshDefinition>newHashMap();
private final ModelManager modelManager;
public ItemModelMesher(ModelManager modelManager)
{
this.modelManager = modelManager;
}
public TextureAtlasSprite getParticleIcon(Item item)
{
return this.getParticleIcon(item, 0);
}
public TextureAtlasSprite getParticleIcon(Item item, int meta)
{
ItemStack stack = new ItemStack(item, 1, meta);
IBakedModel model = this.getItemModel(stack);
return model.getOverrides().handleItemState(model, stack, null, null).getParticleTexture();
}
public IBakedModel getItemModel(ItemStack stack)
{
Item item = stack.getItem();
IBakedModel ibakedmodel = this.getItemModel(item, this.getMetadata(stack));
if (ibakedmodel == null)
{
ItemMeshDefinition itemmeshdefinition = this.shapers.get(item);
if (itemmeshdefinition != null)
{
ibakedmodel = this.modelManager.getModel(itemmeshdefinition.getModelLocation(stack));
}
}
if (ibakedmodel == null)
{
ibakedmodel = this.modelManager.getMissingModel();
}
return ibakedmodel;
}
protected int getMetadata(ItemStack stack)
{
return stack.getMaxDamage() > 0 ? 0 : stack.getMetadata();
}
@Nullable
protected IBakedModel getItemModel(Item item, int meta)
{
return this.simpleShapesCache.get(Integer.valueOf(this.getIndex(item, meta)));
}
private int getIndex(Item item, int meta)
{
return Item.getIdFromItem(item) << 16 | meta;
}
public void register(Item item, int meta, ModelResourceLocation location)
{
this.simpleShapes.put(Integer.valueOf(this.getIndex(item, meta)), location);
this.simpleShapesCache.put(Integer.valueOf(this.getIndex(item, meta)), this.modelManager.getModel(location));
}
public void register(Item item, ItemMeshDefinition definition)
{
this.shapers.put(item, definition);
}
public ModelManager getModelManager()
{
return this.modelManager;
}
public void rebuildCache()
{
this.simpleShapesCache.clear();
for (Entry<Integer, ModelResourceLocation> entry : this.simpleShapes.entrySet())
{
this.simpleShapesCache.put(entry.getKey(), this.modelManager.getModel(entry.getValue()));
}
}
}

View File

@@ -0,0 +1,660 @@
package net.minecraft.client.renderer;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.storage.MapData;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ItemRenderer
{
private static final ResourceLocation RES_MAP_BACKGROUND = new ResourceLocation("textures/map/map_background.png");
private static final ResourceLocation RES_UNDERWATER_OVERLAY = new ResourceLocation("textures/misc/underwater.png");
/** A reference to the Minecraft object. */
private final Minecraft mc;
private ItemStack itemStackMainHand = ItemStack.EMPTY;
private ItemStack itemStackOffHand = ItemStack.EMPTY;
private float equippedProgressMainHand;
private float prevEquippedProgressMainHand;
private float equippedProgressOffHand;
private float prevEquippedProgressOffHand;
private final RenderManager renderManager;
private final RenderItem itemRenderer;
public ItemRenderer(Minecraft mcIn)
{
this.mc = mcIn;
this.renderManager = mcIn.getRenderManager();
this.itemRenderer = mcIn.getRenderItem();
}
public void renderItem(EntityLivingBase entityIn, ItemStack heldStack, ItemCameraTransforms.TransformType transform)
{
this.renderItemSide(entityIn, heldStack, transform, false);
}
public void renderItemSide(EntityLivingBase entitylivingbaseIn, ItemStack heldStack, ItemCameraTransforms.TransformType transform, boolean leftHanded)
{
if (!heldStack.isEmpty())
{
Item item = heldStack.getItem();
Block block = Block.getBlockFromItem(item);
GlStateManager.pushMatrix();
boolean flag = this.itemRenderer.shouldRenderItemIn3D(heldStack) && block.getBlockLayer() == BlockRenderLayer.TRANSLUCENT;
if (flag)
{
GlStateManager.depthMask(false);
}
this.itemRenderer.renderItem(heldStack, entitylivingbaseIn, transform, leftHanded);
if (flag)
{
GlStateManager.depthMask(true);
}
GlStateManager.popMatrix();
}
}
/**
* Rotate the render around X and Y
*/
private void rotateArroundXAndY(float angle, float angleY)
{
GlStateManager.pushMatrix();
GlStateManager.rotate(angle, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(angleY, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GlStateManager.popMatrix();
}
private void setLightmap()
{
AbstractClientPlayer abstractclientplayer = this.mc.player;
int i = this.mc.world.getCombinedLight(new BlockPos(abstractclientplayer.posX, abstractclientplayer.posY + (double)abstractclientplayer.getEyeHeight(), abstractclientplayer.posZ), 0);
float f = (float)(i & 65535);
float f1 = (float)(i >> 16);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, f, f1);
}
private void rotateArm(float p_187458_1_)
{
EntityPlayerSP entityplayersp = this.mc.player;
float f = entityplayersp.prevRenderArmPitch + (entityplayersp.renderArmPitch - entityplayersp.prevRenderArmPitch) * p_187458_1_;
float f1 = entityplayersp.prevRenderArmYaw + (entityplayersp.renderArmYaw - entityplayersp.prevRenderArmYaw) * p_187458_1_;
GlStateManager.rotate((entityplayersp.rotationPitch - f) * 0.1F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate((entityplayersp.rotationYaw - f1) * 0.1F, 0.0F, 1.0F, 0.0F);
}
/**
* Return the angle to render the Map
*/
private float getMapAngleFromPitch(float pitch)
{
float f = 1.0F - pitch / 45.0F + 0.1F;
f = MathHelper.clamp(f, 0.0F, 1.0F);
f = -MathHelper.cos(f * (float)Math.PI) * 0.5F + 0.5F;
return f;
}
private void renderArms()
{
if (!this.mc.player.isInvisible())
{
GlStateManager.disableCull();
GlStateManager.pushMatrix();
GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
this.renderArm(EnumHandSide.RIGHT);
this.renderArm(EnumHandSide.LEFT);
GlStateManager.popMatrix();
GlStateManager.enableCull();
}
}
private void renderArm(EnumHandSide p_187455_1_)
{
this.mc.getTextureManager().bindTexture(this.mc.player.getLocationSkin());
Render<AbstractClientPlayer> render = this.renderManager.<AbstractClientPlayer>getEntityRenderObject(this.mc.player);
RenderPlayer renderplayer = (RenderPlayer)render;
GlStateManager.pushMatrix();
float f = p_187455_1_ == EnumHandSide.RIGHT ? 1.0F : -1.0F;
GlStateManager.rotate(92.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(f * -41.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.translate(f * 0.3F, -1.1F, 0.45F);
if (p_187455_1_ == EnumHandSide.RIGHT)
{
renderplayer.renderRightArm(this.mc.player);
}
else
{
renderplayer.renderLeftArm(this.mc.player);
}
GlStateManager.popMatrix();
}
private void renderMapFirstPersonSide(float p_187465_1_, EnumHandSide hand, float p_187465_3_, ItemStack stack)
{
float f = hand == EnumHandSide.RIGHT ? 1.0F : -1.0F;
GlStateManager.translate(f * 0.125F, -0.125F, 0.0F);
if (!this.mc.player.isInvisible())
{
GlStateManager.pushMatrix();
GlStateManager.rotate(f * 10.0F, 0.0F, 0.0F, 1.0F);
this.renderArmFirstPerson(p_187465_1_, p_187465_3_, hand);
GlStateManager.popMatrix();
}
GlStateManager.pushMatrix();
GlStateManager.translate(f * 0.51F, -0.08F + p_187465_1_ * -1.2F, -0.75F);
float f1 = MathHelper.sqrt(p_187465_3_);
float f2 = MathHelper.sin(f1 * (float)Math.PI);
float f3 = -0.5F * f2;
float f4 = 0.4F * MathHelper.sin(f1 * ((float)Math.PI * 2F));
float f5 = -0.3F * MathHelper.sin(p_187465_3_ * (float)Math.PI);
GlStateManager.translate(f * f3, f4 - 0.3F * f2, f5);
GlStateManager.rotate(f2 * -45.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(f * f2 * -30.0F, 0.0F, 1.0F, 0.0F);
this.renderMapFirstPerson(stack);
GlStateManager.popMatrix();
}
private void renderMapFirstPerson(float p_187463_1_, float p_187463_2_, float p_187463_3_)
{
float f = MathHelper.sqrt(p_187463_3_);
float f1 = -0.2F * MathHelper.sin(p_187463_3_ * (float)Math.PI);
float f2 = -0.4F * MathHelper.sin(f * (float)Math.PI);
GlStateManager.translate(0.0F, -f1 / 2.0F, f2);
float f3 = this.getMapAngleFromPitch(p_187463_1_);
GlStateManager.translate(0.0F, 0.04F + p_187463_2_ * -1.2F + f3 * -0.5F, -0.72F);
GlStateManager.rotate(f3 * -85.0F, 1.0F, 0.0F, 0.0F);
this.renderArms();
float f4 = MathHelper.sin(f * (float)Math.PI);
GlStateManager.rotate(f4 * 20.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.scale(2.0F, 2.0F, 2.0F);
this.renderMapFirstPerson(this.itemStackMainHand);
}
private void renderMapFirstPerson(ItemStack stack)
{
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.scale(0.38F, 0.38F, 0.38F);
GlStateManager.disableLighting();
this.mc.getTextureManager().bindTexture(RES_MAP_BACKGROUND);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
GlStateManager.translate(-0.5F, -0.5F, 0.0F);
GlStateManager.scale(0.0078125F, 0.0078125F, 0.0078125F);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(-7.0D, 135.0D, 0.0D).tex(0.0D, 1.0D).endVertex();
bufferbuilder.pos(135.0D, 135.0D, 0.0D).tex(1.0D, 1.0D).endVertex();
bufferbuilder.pos(135.0D, -7.0D, 0.0D).tex(1.0D, 0.0D).endVertex();
bufferbuilder.pos(-7.0D, -7.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
tessellator.draw();
MapData mapdata = ((net.minecraft.item.ItemMap) stack.getItem()).getMapData(stack, this.mc.world);
if (mapdata != null)
{
this.mc.entityRenderer.getMapItemRenderer().renderMap(mapdata, false);
}
GlStateManager.enableLighting();
}
private void renderArmFirstPerson(float p_187456_1_, float p_187456_2_, EnumHandSide p_187456_3_)
{
boolean flag = p_187456_3_ != EnumHandSide.LEFT;
float f = flag ? 1.0F : -1.0F;
float f1 = MathHelper.sqrt(p_187456_2_);
float f2 = -0.3F * MathHelper.sin(f1 * (float)Math.PI);
float f3 = 0.4F * MathHelper.sin(f1 * ((float)Math.PI * 2F));
float f4 = -0.4F * MathHelper.sin(p_187456_2_ * (float)Math.PI);
GlStateManager.translate(f * (f2 + 0.64000005F), f3 + -0.6F + p_187456_1_ * -0.6F, f4 + -0.71999997F);
GlStateManager.rotate(f * 45.0F, 0.0F, 1.0F, 0.0F);
float f5 = MathHelper.sin(p_187456_2_ * p_187456_2_ * (float)Math.PI);
float f6 = MathHelper.sin(f1 * (float)Math.PI);
GlStateManager.rotate(f * f6 * 70.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(f * f5 * -20.0F, 0.0F, 0.0F, 1.0F);
AbstractClientPlayer abstractclientplayer = this.mc.player;
this.mc.getTextureManager().bindTexture(abstractclientplayer.getLocationSkin());
GlStateManager.translate(f * -1.0F, 3.6F, 3.5F);
GlStateManager.rotate(f * 120.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(200.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(f * -135.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(f * 5.6F, 0.0F, 0.0F);
RenderPlayer renderplayer = (RenderPlayer)this.renderManager.<AbstractClientPlayer>getEntityRenderObject(abstractclientplayer);
GlStateManager.disableCull();
if (flag)
{
renderplayer.renderRightArm(abstractclientplayer);
}
else
{
renderplayer.renderLeftArm(abstractclientplayer);
}
GlStateManager.enableCull();
}
private void transformEatFirstPerson(float p_187454_1_, EnumHandSide hand, ItemStack stack)
{
float f = (float)this.mc.player.getItemInUseCount() - p_187454_1_ + 1.0F;
float f1 = f / (float)stack.getMaxItemUseDuration();
if (f1 < 0.8F)
{
float f2 = MathHelper.abs(MathHelper.cos(f / 4.0F * (float)Math.PI) * 0.1F);
GlStateManager.translate(0.0F, f2, 0.0F);
}
float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
int i = hand == EnumHandSide.RIGHT ? 1 : -1;
GlStateManager.translate(f3 * 0.6F * (float)i, f3 * -0.5F, f3 * 0.0F);
GlStateManager.rotate((float)i * f3 * 90.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate((float)i * f3 * 30.0F, 0.0F, 0.0F, 1.0F);
}
private void transformFirstPerson(EnumHandSide hand, float p_187453_2_)
{
int i = hand == EnumHandSide.RIGHT ? 1 : -1;
float f = MathHelper.sin(p_187453_2_ * p_187453_2_ * (float)Math.PI);
GlStateManager.rotate((float)i * (45.0F + f * -20.0F), 0.0F, 1.0F, 0.0F);
float f1 = MathHelper.sin(MathHelper.sqrt(p_187453_2_) * (float)Math.PI);
GlStateManager.rotate((float)i * f1 * -20.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(f1 * -80.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate((float)i * -45.0F, 0.0F, 1.0F, 0.0F);
}
private void transformSideFirstPerson(EnumHandSide hand, float p_187459_2_)
{
int i = hand == EnumHandSide.RIGHT ? 1 : -1;
GlStateManager.translate((float)i * 0.56F, -0.52F + p_187459_2_ * -0.6F, -0.72F);
}
/**
* Renders the active item in the player's hand when in first person mode.
*/
public void renderItemInFirstPerson(float partialTicks)
{
AbstractClientPlayer abstractclientplayer = this.mc.player;
float f = abstractclientplayer.getSwingProgress(partialTicks);
EnumHand enumhand = (EnumHand)MoreObjects.firstNonNull(abstractclientplayer.swingingHand, EnumHand.MAIN_HAND);
float f1 = abstractclientplayer.prevRotationPitch + (abstractclientplayer.rotationPitch - abstractclientplayer.prevRotationPitch) * partialTicks;
float f2 = abstractclientplayer.prevRotationYaw + (abstractclientplayer.rotationYaw - abstractclientplayer.prevRotationYaw) * partialTicks;
boolean flag = true;
boolean flag1 = true;
if (abstractclientplayer.isHandActive())
{
ItemStack itemstack = abstractclientplayer.getActiveItemStack();
if (!itemstack.isEmpty() && itemstack.getItem() == Items.BOW) //Forge: Data watcher can desync and cause this to NPE...
{
EnumHand enumhand1 = abstractclientplayer.getActiveHand();
flag = enumhand1 == EnumHand.MAIN_HAND;
flag1 = !flag;
}
}
this.rotateArroundXAndY(f1, f2);
this.setLightmap();
this.rotateArm(partialTicks);
GlStateManager.enableRescaleNormal();
if (flag)
{
float f3 = enumhand == EnumHand.MAIN_HAND ? f : 0.0F;
float f5 = 1.0F - (this.prevEquippedProgressMainHand + (this.equippedProgressMainHand - this.prevEquippedProgressMainHand) * partialTicks);
if(!net.minecraftforge.client.ForgeHooksClient.renderSpecificFirstPersonHand(EnumHand.MAIN_HAND, partialTicks, f1, f3, f5, this.itemStackMainHand))
this.renderItemInFirstPerson(abstractclientplayer, partialTicks, f1, EnumHand.MAIN_HAND, f3, this.itemStackMainHand, f5);
}
if (flag1)
{
float f4 = enumhand == EnumHand.OFF_HAND ? f : 0.0F;
float f6 = 1.0F - (this.prevEquippedProgressOffHand + (this.equippedProgressOffHand - this.prevEquippedProgressOffHand) * partialTicks);
if(!net.minecraftforge.client.ForgeHooksClient.renderSpecificFirstPersonHand(EnumHand.OFF_HAND, partialTicks, f1, f4, f6, this.itemStackOffHand))
this.renderItemInFirstPerson(abstractclientplayer, partialTicks, f1, EnumHand.OFF_HAND, f4, this.itemStackOffHand, f6);
}
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
}
public void renderItemInFirstPerson(AbstractClientPlayer player, float p_187457_2_, float p_187457_3_, EnumHand hand, float p_187457_5_, ItemStack stack, float p_187457_7_)
{
boolean flag = hand == EnumHand.MAIN_HAND;
EnumHandSide enumhandside = flag ? player.getPrimaryHand() : player.getPrimaryHand().opposite();
GlStateManager.pushMatrix();
if (stack.isEmpty())
{
if (flag && !player.isInvisible())
{
this.renderArmFirstPerson(p_187457_7_, p_187457_5_, enumhandside);
}
}
else if (stack.getItem() instanceof net.minecraft.item.ItemMap)
{
if (flag && this.itemStackOffHand.isEmpty())
{
this.renderMapFirstPerson(p_187457_3_, p_187457_7_, p_187457_5_);
}
else
{
this.renderMapFirstPersonSide(p_187457_7_, enumhandside, p_187457_5_, stack);
}
}
else
{
boolean flag1 = enumhandside == EnumHandSide.RIGHT;
if (player.isHandActive() && player.getItemInUseCount() > 0 && player.getActiveHand() == hand)
{
int j = flag1 ? 1 : -1;
switch (stack.getItemUseAction())
{
case NONE:
this.transformSideFirstPerson(enumhandside, p_187457_7_);
break;
case EAT:
case DRINK:
this.transformEatFirstPerson(p_187457_2_, enumhandside, stack);
this.transformSideFirstPerson(enumhandside, p_187457_7_);
break;
case BLOCK:
this.transformSideFirstPerson(enumhandside, p_187457_7_);
break;
case BOW:
this.transformSideFirstPerson(enumhandside, p_187457_7_);
GlStateManager.translate((float)j * -0.2785682F, 0.18344387F, 0.15731531F);
GlStateManager.rotate(-13.935F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate((float)j * 35.3F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate((float)j * -9.785F, 0.0F, 0.0F, 1.0F);
float f5 = (float)stack.getMaxItemUseDuration() - ((float)this.mc.player.getItemInUseCount() - p_187457_2_ + 1.0F);
float f6 = f5 / 20.0F;
f6 = (f6 * f6 + f6 * 2.0F) / 3.0F;
if (f6 > 1.0F)
{
f6 = 1.0F;
}
if (f6 > 0.1F)
{
float f7 = MathHelper.sin((f5 - 0.1F) * 1.3F);
float f3 = f6 - 0.1F;
float f4 = f7 * f3;
GlStateManager.translate(f4 * 0.0F, f4 * 0.004F, f4 * 0.0F);
}
GlStateManager.translate(f6 * 0.0F, f6 * 0.0F, f6 * 0.04F);
GlStateManager.scale(1.0F, 1.0F, 1.0F + f6 * 0.2F);
GlStateManager.rotate((float)j * 45.0F, 0.0F, -1.0F, 0.0F);
}
}
else
{
float f = -0.4F * MathHelper.sin(MathHelper.sqrt(p_187457_5_) * (float)Math.PI);
float f1 = 0.2F * MathHelper.sin(MathHelper.sqrt(p_187457_5_) * ((float)Math.PI * 2F));
float f2 = -0.2F * MathHelper.sin(p_187457_5_ * (float)Math.PI);
int i = flag1 ? 1 : -1;
GlStateManager.translate((float)i * f, f1, f2);
this.transformSideFirstPerson(enumhandside, p_187457_7_);
this.transformFirstPerson(enumhandside, p_187457_5_);
}
this.renderItemSide(player, stack, flag1 ? ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND : ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND, !flag1);
}
GlStateManager.popMatrix();
}
/**
* Renders the overlays.
*/
public void renderOverlays(float partialTicks)
{
GlStateManager.disableAlpha();
if (this.mc.player.isEntityInsideOpaqueBlock())
{
IBlockState iblockstate = this.mc.world.getBlockState(new BlockPos(this.mc.player));
BlockPos overlayPos = new BlockPos(this.mc.player);
EntityPlayer entityplayer = this.mc.player;
for (int i = 0; i < 8; ++i)
{
double d0 = entityplayer.posX + (double)(((float)((i >> 0) % 2) - 0.5F) * entityplayer.width * 0.8F);
double d1 = entityplayer.posY + (double)(((float)((i >> 1) % 2) - 0.5F) * 0.1F);
double d2 = entityplayer.posZ + (double)(((float)((i >> 2) % 2) - 0.5F) * entityplayer.width * 0.8F);
BlockPos blockpos = new BlockPos(d0, d1 + (double)entityplayer.getEyeHeight(), d2);
IBlockState iblockstate1 = this.mc.world.getBlockState(blockpos);
if (iblockstate1.causesSuffocation())
{
iblockstate = iblockstate1;
overlayPos = blockpos;
}
}
if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE)
{
if (!net.minecraftforge.event.ForgeEventFactory.renderBlockOverlay(mc.player, partialTicks, net.minecraftforge.client.event.RenderBlockOverlayEvent.OverlayType.BLOCK, iblockstate, overlayPos))
this.renderBlockInHand(this.mc.getBlockRendererDispatcher().getBlockModelShapes().getTexture(iblockstate));
}
}
if (!this.mc.player.isSpectator())
{
if (this.mc.player.isInsideOfMaterial(Material.WATER))
{
if (!net.minecraftforge.event.ForgeEventFactory.renderWaterOverlay(mc.player, partialTicks))
this.renderWaterOverlayTexture(partialTicks);
}
if (this.mc.player.isBurning())
{
if (!net.minecraftforge.event.ForgeEventFactory.renderFireOverlay(mc.player, partialTicks))
this.renderFireInFirstPerson();
}
}
GlStateManager.enableAlpha();
}
/**
* Render the block in the player's hand
*/
private void renderBlockInHand(TextureAtlasSprite sprite)
{
this.mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
float f = 0.1F;
GlStateManager.color(0.1F, 0.1F, 0.1F, 0.5F);
GlStateManager.pushMatrix();
float f1 = -1.0F;
float f2 = 1.0F;
float f3 = -1.0F;
float f4 = 1.0F;
float f5 = -0.5F;
float f6 = sprite.getMinU();
float f7 = sprite.getMaxU();
float f8 = sprite.getMinV();
float f9 = sprite.getMaxV();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(-1.0D, -1.0D, -0.5D).tex((double)f7, (double)f9).endVertex();
bufferbuilder.pos(1.0D, -1.0D, -0.5D).tex((double)f6, (double)f9).endVertex();
bufferbuilder.pos(1.0D, 1.0D, -0.5D).tex((double)f6, (double)f8).endVertex();
bufferbuilder.pos(-1.0D, 1.0D, -0.5D).tex((double)f7, (double)f8).endVertex();
tessellator.draw();
GlStateManager.popMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
}
/**
* Renders a texture that warps around based on the direction the player is looking. Texture needs to be bound
* before being called. Used for the water overlay.
*/
private void renderWaterOverlayTexture(float partialTicks)
{
this.mc.getTextureManager().bindTexture(RES_UNDERWATER_OVERLAY);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
float f = this.mc.player.getBrightness();
GlStateManager.color(f, f, f, 0.5F);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.pushMatrix();
float f1 = 4.0F;
float f2 = -1.0F;
float f3 = 1.0F;
float f4 = -1.0F;
float f5 = 1.0F;
float f6 = -0.5F;
float f7 = -this.mc.player.rotationYaw / 64.0F;
float f8 = this.mc.player.rotationPitch / 64.0F;
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(-1.0D, -1.0D, -0.5D).tex((double)(4.0F + f7), (double)(4.0F + f8)).endVertex();
bufferbuilder.pos(1.0D, -1.0D, -0.5D).tex((double)(0.0F + f7), (double)(4.0F + f8)).endVertex();
bufferbuilder.pos(1.0D, 1.0D, -0.5D).tex((double)(0.0F + f7), (double)(0.0F + f8)).endVertex();
bufferbuilder.pos(-1.0D, 1.0D, -0.5D).tex((double)(4.0F + f7), (double)(0.0F + f8)).endVertex();
tessellator.draw();
GlStateManager.popMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableBlend();
}
/**
* Renders the fire on the screen for first person mode. Arg: partialTickTime
*/
private void renderFireInFirstPerson()
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
GlStateManager.color(1.0F, 1.0F, 1.0F, 0.9F);
GlStateManager.depthFunc(519);
GlStateManager.depthMask(false);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
float f = 1.0F;
for (int i = 0; i < 2; ++i)
{
GlStateManager.pushMatrix();
TextureAtlasSprite textureatlassprite = this.mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_1");
this.mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
float f1 = textureatlassprite.getMinU();
float f2 = textureatlassprite.getMaxU();
float f3 = textureatlassprite.getMinV();
float f4 = textureatlassprite.getMaxV();
float f5 = -0.5F;
float f6 = 0.5F;
float f7 = -0.5F;
float f8 = 0.5F;
float f9 = -0.5F;
GlStateManager.translate((float)(-(i * 2 - 1)) * 0.24F, -0.3F, 0.0F);
GlStateManager.rotate((float)(i * 2 - 1) * 10.0F, 0.0F, 1.0F, 0.0F);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(-0.5D, -0.5D, -0.5D).tex((double)f2, (double)f4).endVertex();
bufferbuilder.pos(0.5D, -0.5D, -0.5D).tex((double)f1, (double)f4).endVertex();
bufferbuilder.pos(0.5D, 0.5D, -0.5D).tex((double)f1, (double)f3).endVertex();
bufferbuilder.pos(-0.5D, 0.5D, -0.5D).tex((double)f2, (double)f3).endVertex();
tessellator.draw();
GlStateManager.popMatrix();
}
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableBlend();
GlStateManager.depthMask(true);
GlStateManager.depthFunc(515);
}
public void updateEquippedItem()
{
this.prevEquippedProgressMainHand = this.equippedProgressMainHand;
this.prevEquippedProgressOffHand = this.equippedProgressOffHand;
EntityPlayerSP entityplayersp = this.mc.player;
ItemStack itemstack = entityplayersp.getHeldItemMainhand();
ItemStack itemstack1 = entityplayersp.getHeldItemOffhand();
if (entityplayersp.isRowingBoat())
{
this.equippedProgressMainHand = MathHelper.clamp(this.equippedProgressMainHand - 0.4F, 0.0F, 1.0F);
this.equippedProgressOffHand = MathHelper.clamp(this.equippedProgressOffHand - 0.4F, 0.0F, 1.0F);
}
else
{
float f = entityplayersp.getCooledAttackStrength(1.0F);
boolean requipM = net.minecraftforge.client.ForgeHooksClient.shouldCauseReequipAnimation(this.itemStackMainHand, itemstack, entityplayersp.inventory.currentItem);
boolean requipO = net.minecraftforge.client.ForgeHooksClient.shouldCauseReequipAnimation(this.itemStackOffHand, itemstack1, -1);
if (!requipM && !Objects.equals(this.itemStackMainHand, itemstack))
this.itemStackMainHand = itemstack;
if (!requipM && !Objects.equals(this.itemStackOffHand, itemstack1))
this.itemStackOffHand = itemstack1;
this.equippedProgressMainHand += MathHelper.clamp((!requipM ? f * f * f : 0.0F) - this.equippedProgressMainHand, -0.4F, 0.4F);
this.equippedProgressOffHand += MathHelper.clamp((float)(!requipO ? 1 : 0) - this.equippedProgressOffHand, -0.4F, 0.4F);
}
if (this.equippedProgressMainHand < 0.1F)
{
this.itemStackMainHand = itemstack;
}
if (this.equippedProgressOffHand < 0.1F)
{
this.itemStackOffHand = itemstack1;
}
}
public void resetEquippedProgress(EnumHand hand)
{
if (hand == EnumHand.MAIN_HAND)
{
this.equippedProgressMainHand = 0.0F;
}
else
{
this.equippedProgressOffHand = 0.0F;
}
}
}

View File

@@ -0,0 +1,48 @@
package net.minecraft.client.renderer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Matrix4f extends org.lwjgl.util.vector.Matrix4f
{
public Matrix4f(float[] matrix)
{
this.m00 = matrix[0];
this.m01 = matrix[1];
this.m02 = matrix[2];
this.m03 = matrix[3];
this.m10 = matrix[4];
this.m11 = matrix[5];
this.m12 = matrix[6];
this.m13 = matrix[7];
this.m20 = matrix[8];
this.m21 = matrix[9];
this.m22 = matrix[10];
this.m23 = matrix[11];
this.m30 = matrix[12];
this.m31 = matrix[13];
this.m32 = matrix[14];
this.m33 = matrix[15];
}
public Matrix4f()
{
this.m00 = 0.0F;
this.m01 = 0.0F;
this.m02 = 0.0F;
this.m03 = 0.0F;
this.m10 = 0.0F;
this.m11 = 0.0F;
this.m12 = 0.0F;
this.m13 = 0.0F;
this.m20 = 0.0F;
this.m21 = 0.0F;
this.m22 = 0.0F;
this.m23 = 0.0F;
this.m30 = 0.0F;
this.m31 = 0.0F;
this.m32 = 0.0F;
this.m33 = 0.0F;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
package net.minecraft.client.renderer;
import net.minecraft.util.BlockRenderLayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RegionRenderCacheBuilder
{
private final BufferBuilder[] worldRenderers = new BufferBuilder[BlockRenderLayer.values().length];
public RegionRenderCacheBuilder()
{
this.worldRenderers[BlockRenderLayer.SOLID.ordinal()] = new BufferBuilder(2097152);
this.worldRenderers[BlockRenderLayer.CUTOUT.ordinal()] = new BufferBuilder(131072);
this.worldRenderers[BlockRenderLayer.CUTOUT_MIPPED.ordinal()] = new BufferBuilder(131072);
this.worldRenderers[BlockRenderLayer.TRANSLUCENT.ordinal()] = new BufferBuilder(262144);
}
public BufferBuilder getWorldRendererByLayer(BlockRenderLayer layer)
{
return this.worldRenderers[layer.ordinal()];
}
public BufferBuilder getWorldRendererByLayerId(int id)
{
return this.worldRenderers[id];
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,81 @@
package net.minecraft.client.renderer;
import java.nio.FloatBuffer;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderHelper
{
/** Float buffer used to set OpenGL material colors */
private static final FloatBuffer COLOR_BUFFER = GLAllocation.createDirectFloatBuffer(4);
private static final Vec3d LIGHT0_POS = (new Vec3d(0.20000000298023224D, 1.0D, -0.699999988079071D)).normalize();
private static final Vec3d LIGHT1_POS = (new Vec3d(-0.20000000298023224D, 1.0D, 0.699999988079071D)).normalize();
/**
* Disables the OpenGL lighting properties enabled by enableStandardItemLighting
*/
public static void disableStandardItemLighting()
{
GlStateManager.disableLighting();
GlStateManager.disableLight(0);
GlStateManager.disableLight(1);
GlStateManager.disableColorMaterial();
}
/**
* Sets the OpenGL lighting properties to the values used when rendering blocks as items
*/
public static void enableStandardItemLighting()
{
GlStateManager.enableLighting();
GlStateManager.enableLight(0);
GlStateManager.enableLight(1);
GlStateManager.enableColorMaterial();
GlStateManager.colorMaterial(1032, 5634);
GlStateManager.glLight(16384, 4611, setColorBuffer(LIGHT0_POS.x, LIGHT0_POS.y, LIGHT0_POS.z, 0.0D));
float f = 0.6F;
GlStateManager.glLight(16384, 4609, setColorBuffer(0.6F, 0.6F, 0.6F, 1.0F));
GlStateManager.glLight(16384, 4608, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
GlStateManager.glLight(16384, 4610, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
GlStateManager.glLight(16385, 4611, setColorBuffer(LIGHT1_POS.x, LIGHT1_POS.y, LIGHT1_POS.z, 0.0D));
GlStateManager.glLight(16385, 4609, setColorBuffer(0.6F, 0.6F, 0.6F, 1.0F));
GlStateManager.glLight(16385, 4608, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
GlStateManager.glLight(16385, 4610, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
GlStateManager.shadeModel(7424);
float f1 = 0.4F;
GlStateManager.glLightModel(2899, setColorBuffer(0.4F, 0.4F, 0.4F, 1.0F));
}
/**
* Update and return colorBuffer with the RGBA values passed as arguments
*/
private static FloatBuffer setColorBuffer(double p_74517_0_, double p_74517_2_, double p_74517_4_, double p_74517_6_)
{
return setColorBuffer((float)p_74517_0_, (float)p_74517_2_, (float)p_74517_4_, (float)p_74517_6_);
}
/**
* Update and return colorBuffer with the RGBA values passed as arguments
*/
public static FloatBuffer setColorBuffer(float p_74521_0_, float p_74521_1_, float p_74521_2_, float p_74521_3_)
{
COLOR_BUFFER.clear();
COLOR_BUFFER.put(p_74521_0_).put(p_74521_1_).put(p_74521_2_).put(p_74521_3_);
COLOR_BUFFER.flip();
return COLOR_BUFFER;
}
/**
* Sets OpenGL lighting for rendering blocks as items inside GUI screens (such as containers).
*/
public static void enableGUIStandardItemLighting()
{
GlStateManager.pushMatrix();
GlStateManager.rotate(-30.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(165.0F, 1.0F, 0.0F, 0.0F);
enableStandardItemLighting();
GlStateManager.popMatrix();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
package net.minecraft.client.renderer;
import net.minecraft.client.renderer.chunk.ListedRenderChunk;
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.util.BlockRenderLayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderList extends ChunkRenderContainer
{
public void renderChunkLayer(BlockRenderLayer layer)
{
if (this.initialized)
{
for (RenderChunk renderchunk : this.renderChunks)
{
ListedRenderChunk listedrenderchunk = (ListedRenderChunk)renderchunk;
GlStateManager.pushMatrix();
this.preRenderChunk(renderchunk);
GlStateManager.callList(listedrenderchunk.getDisplayList(layer, listedrenderchunk.getCompiledChunk()));
GlStateManager.popMatrix();
}
GlStateManager.resetColor();
this.renderChunks.clear();
}
}
}

View File

@@ -0,0 +1,17 @@
package net.minecraft.client.renderer;
import net.minecraft.client.renderer.texture.Stitcher;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class StitcherException extends RuntimeException
{
private final Stitcher.Holder holder;
public StitcherException(Stitcher.Holder holderIn, String message)
{
super(message);
this.holder = holderIn;
}
}

View File

@@ -0,0 +1,37 @@
package net.minecraft.client.renderer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Tessellator
{
private final BufferBuilder buffer;
private final WorldVertexBufferUploader vboUploader = new WorldVertexBufferUploader();
/** The static instance of the Tessellator. */
private static final Tessellator INSTANCE = new Tessellator(2097152);
public static Tessellator getInstance()
{
return INSTANCE;
}
public Tessellator(int bufferSize)
{
this.buffer = new BufferBuilder(bufferSize);
}
/**
* Draws the data set up in this tessellator and resets the state to prepare for new drawing.
*/
public void draw()
{
this.buffer.finishDrawing();
this.vboUploader.draw(this.buffer);
}
public BufferBuilder getBuffer()
{
return this.buffer;
}
}

View File

@@ -0,0 +1,170 @@
package net.minecraft.client.renderer;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class ThreadDownloadImageData extends SimpleTexture
{
private static final Logger LOGGER = LogManager.getLogger();
private static final AtomicInteger TEXTURE_DOWNLOADER_THREAD_ID = new AtomicInteger(0);
@Nullable
private final File cacheFile;
private final String imageUrl;
@Nullable
private final IImageBuffer imageBuffer;
@Nullable
private BufferedImage bufferedImage;
@Nullable
private Thread imageThread;
private boolean textureUploaded;
public ThreadDownloadImageData(@Nullable File cacheFileIn, String imageUrlIn, ResourceLocation textureResourceLocation, @Nullable IImageBuffer imageBufferIn)
{
super(textureResourceLocation);
this.cacheFile = cacheFileIn;
this.imageUrl = imageUrlIn;
this.imageBuffer = imageBufferIn;
}
private void checkTextureUploaded()
{
if (!this.textureUploaded)
{
if (this.bufferedImage != null)
{
if (this.textureLocation != null)
{
this.deleteGlTexture();
}
TextureUtil.uploadTextureImage(super.getGlTextureId(), this.bufferedImage);
this.textureUploaded = true;
}
}
}
public int getGlTextureId()
{
this.checkTextureUploaded();
return super.getGlTextureId();
}
public void setBufferedImage(BufferedImage bufferedImageIn)
{
this.bufferedImage = bufferedImageIn;
if (this.imageBuffer != null)
{
this.imageBuffer.skinAvailable();
}
}
public void loadTexture(IResourceManager resourceManager) throws IOException
{
if (this.bufferedImage == null && this.textureLocation != null)
{
super.loadTexture(resourceManager);
}
if (this.imageThread == null)
{
if (this.cacheFile != null && this.cacheFile.isFile())
{
LOGGER.debug("Loading http texture from local cache ({})", (Object)this.cacheFile);
try
{
this.bufferedImage = ImageIO.read(this.cacheFile);
if (this.imageBuffer != null)
{
this.setBufferedImage(this.imageBuffer.parseUserSkin(this.bufferedImage));
}
}
catch (IOException ioexception)
{
LOGGER.error("Couldn't load skin {}", this.cacheFile, ioexception);
this.loadTextureFromServer();
}
}
else
{
this.loadTextureFromServer();
}
}
}
protected void loadTextureFromServer()
{
this.imageThread = new Thread("Texture Downloader #" + TEXTURE_DOWNLOADER_THREAD_ID.incrementAndGet())
{
public void run()
{
HttpURLConnection httpurlconnection = null;
ThreadDownloadImageData.LOGGER.debug("Downloading http texture from {} to {}", ThreadDownloadImageData.this.imageUrl, ThreadDownloadImageData.this.cacheFile);
try
{
httpurlconnection = (HttpURLConnection)(new URL(ThreadDownloadImageData.this.imageUrl)).openConnection(Minecraft.getMinecraft().getProxy());
httpurlconnection.setDoInput(true);
httpurlconnection.setDoOutput(false);
httpurlconnection.connect();
if (httpurlconnection.getResponseCode() / 100 == 2)
{
BufferedImage bufferedimage;
if (ThreadDownloadImageData.this.cacheFile != null)
{
FileUtils.copyInputStreamToFile(httpurlconnection.getInputStream(), ThreadDownloadImageData.this.cacheFile);
bufferedimage = ImageIO.read(ThreadDownloadImageData.this.cacheFile);
}
else
{
bufferedimage = TextureUtil.readBufferedImage(httpurlconnection.getInputStream());
}
if (ThreadDownloadImageData.this.imageBuffer != null)
{
bufferedimage = ThreadDownloadImageData.this.imageBuffer.parseUserSkin(bufferedimage);
}
ThreadDownloadImageData.this.setBufferedImage(bufferedimage);
return;
}
}
catch (Exception exception)
{
ThreadDownloadImageData.LOGGER.error("Couldn't download http texture", (Throwable)exception);
return;
}
finally
{
if (httpurlconnection != null)
{
httpurlconnection.disconnect();
}
}
}
};
this.imageThread.setDaemon(true);
this.imageThread.start();
}
}

View File

@@ -0,0 +1,43 @@
package net.minecraft.client.renderer;
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.client.renderer.vertex.VertexBuffer;
import net.minecraft.util.BlockRenderLayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class VboRenderList extends ChunkRenderContainer
{
public void renderChunkLayer(BlockRenderLayer layer)
{
if (this.initialized)
{
for (RenderChunk renderchunk : this.renderChunks)
{
VertexBuffer vertexbuffer = renderchunk.getVertexBufferByLayer(layer.ordinal());
GlStateManager.pushMatrix();
this.preRenderChunk(renderchunk);
renderchunk.multModelviewMatrix();
vertexbuffer.bindBuffer();
this.setupArrayPointers();
vertexbuffer.drawArrays(7);
GlStateManager.popMatrix();
}
OpenGlHelper.glBindBuffer(OpenGlHelper.GL_ARRAY_BUFFER, 0);
GlStateManager.resetColor();
this.renderChunks.clear();
}
}
private void setupArrayPointers()
{
GlStateManager.glVertexPointer(3, 5126, 28, 0);
GlStateManager.glColorPointer(4, 5121, 28, 12);
GlStateManager.glTexCoordPointer(2, 5126, 28, 16);
OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
GlStateManager.glTexCoordPointer(2, 5122, 28, 24);
OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
}
}

View File

@@ -0,0 +1,15 @@
package net.minecraft.client.renderer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Vector3d
{
/** The X coordinate */
public double x;
/** The Y coordinate */
public double y;
/** The Z coordinate */
public double z;
}

View File

@@ -0,0 +1,22 @@
package net.minecraft.client.renderer;
import net.minecraft.client.renderer.vertex.VertexBuffer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class VertexBufferUploader extends WorldVertexBufferUploader
{
private VertexBuffer vertexBuffer;
public void draw(BufferBuilder bufferBuilderIn)
{
bufferBuilderIn.reset();
this.vertexBuffer.bufferData(bufferBuilderIn.getByteBuffer());
}
public void setVertexBuffer(VertexBuffer vertexBufferIn)
{
this.vertexBuffer = vertexBufferIn;
}
}

View File

@@ -0,0 +1,178 @@
package net.minecraft.client.renderer;
import javax.annotation.Nullable;
import net.minecraft.client.renderer.chunk.IRenderChunkFactory;
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ViewFrustum
{
protected final RenderGlobal renderGlobal;
protected final World world;
protected int countChunksY;
protected int countChunksX;
protected int countChunksZ;
public RenderChunk[] renderChunks;
public ViewFrustum(World worldIn, int renderDistanceChunks, RenderGlobal renderGlobalIn, IRenderChunkFactory renderChunkFactory)
{
this.renderGlobal = renderGlobalIn;
this.world = worldIn;
this.setCountChunksXYZ(renderDistanceChunks);
this.createRenderChunks(renderChunkFactory);
}
protected void createRenderChunks(IRenderChunkFactory renderChunkFactory)
{
int i = this.countChunksX * this.countChunksY * this.countChunksZ;
this.renderChunks = new RenderChunk[i];
int j = 0;
for (int k = 0; k < this.countChunksX; ++k)
{
for (int l = 0; l < this.countChunksY; ++l)
{
for (int i1 = 0; i1 < this.countChunksZ; ++i1)
{
int j1 = (i1 * this.countChunksY + l) * this.countChunksX + k;
this.renderChunks[j1] = renderChunkFactory.create(this.world, this.renderGlobal, j++);
this.renderChunks[j1].setPosition(k * 16, l * 16, i1 * 16);
}
}
}
}
public void deleteGlResources()
{
for (RenderChunk renderchunk : this.renderChunks)
{
renderchunk.deleteGlResources();
}
}
protected void setCountChunksXYZ(int renderDistanceChunks)
{
int i = renderDistanceChunks * 2 + 1;
this.countChunksX = i;
this.countChunksY = 16;
this.countChunksZ = i;
}
public void updateChunkPositions(double viewEntityX, double viewEntityZ)
{
int i = MathHelper.floor(viewEntityX) - 8;
int j = MathHelper.floor(viewEntityZ) - 8;
int k = this.countChunksX * 16;
for (int l = 0; l < this.countChunksX; ++l)
{
int i1 = this.getBaseCoordinate(i, k, l);
for (int j1 = 0; j1 < this.countChunksZ; ++j1)
{
int k1 = this.getBaseCoordinate(j, k, j1);
for (int l1 = 0; l1 < this.countChunksY; ++l1)
{
int i2 = l1 * 16;
RenderChunk renderchunk = this.renderChunks[(j1 * this.countChunksY + l1) * this.countChunksX + l];
renderchunk.setPosition(i1, i2, k1);
}
}
}
}
private int getBaseCoordinate(int p_178157_1_, int p_178157_2_, int p_178157_3_)
{
int i = p_178157_3_ * 16;
int j = i - p_178157_1_ + p_178157_2_ / 2;
if (j < 0)
{
j -= p_178157_2_ - 1;
}
return i - j / p_178157_2_ * p_178157_2_;
}
public void markBlocksForUpdate(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, boolean updateImmediately)
{
int i = MathHelper.intFloorDiv(minX, 16);
int j = MathHelper.intFloorDiv(minY, 16);
int k = MathHelper.intFloorDiv(minZ, 16);
int l = MathHelper.intFloorDiv(maxX, 16);
int i1 = MathHelper.intFloorDiv(maxY, 16);
int j1 = MathHelper.intFloorDiv(maxZ, 16);
for (int k1 = i; k1 <= l; ++k1)
{
int l1 = k1 % this.countChunksX;
if (l1 < 0)
{
l1 += this.countChunksX;
}
for (int i2 = j; i2 <= i1; ++i2)
{
int j2 = i2 % this.countChunksY;
if (j2 < 0)
{
j2 += this.countChunksY;
}
for (int k2 = k; k2 <= j1; ++k2)
{
int l2 = k2 % this.countChunksZ;
if (l2 < 0)
{
l2 += this.countChunksZ;
}
int i3 = (l2 * this.countChunksY + j2) * this.countChunksX + l1;
RenderChunk renderchunk = this.renderChunks[i3];
renderchunk.setNeedsUpdate(updateImmediately);
}
}
}
}
@Nullable
protected RenderChunk getRenderChunk(BlockPos pos)
{
int i = MathHelper.intFloorDiv(pos.getX(), 16);
int j = MathHelper.intFloorDiv(pos.getY(), 16);
int k = MathHelper.intFloorDiv(pos.getZ(), 16);
if (j >= 0 && j < this.countChunksY)
{
i = i % this.countChunksX;
if (i < 0)
{
i += this.countChunksX;
}
k = k % this.countChunksZ;
if (k < 0)
{
k += this.countChunksZ;
}
int l = (k * this.countChunksY + j) * this.countChunksX + i;
return this.renderChunks[l];
}
else
{
return null;
}
}
}

View File

@@ -0,0 +1,50 @@
package net.minecraft.client.renderer;
import java.nio.ByteBuffer;
import java.util.List;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class WorldVertexBufferUploader
{
public void draw(BufferBuilder bufferBuilderIn)
{
if (bufferBuilderIn.getVertexCount() > 0)
{
VertexFormat vertexformat = bufferBuilderIn.getVertexFormat();
int i = vertexformat.getNextOffset();
ByteBuffer bytebuffer = bufferBuilderIn.getByteBuffer();
List<VertexFormatElement> list = vertexformat.getElements();
for (int j = 0; j < list.size(); ++j)
{
VertexFormatElement vertexformatelement = list.get(j);
VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.getUsage();
int k = vertexformatelement.getType().getGlConstant();
int l = vertexformatelement.getIndex();
bytebuffer.position(vertexformat.getOffset(j));
// moved to VertexFormatElement.preDraw
vertexformatelement.getUsage().preDraw(vertexformat, j, i, bytebuffer);
}
GlStateManager.glDrawArrays(bufferBuilderIn.getDrawMode(), 0, bufferBuilderIn.getVertexCount());
int i1 = 0;
for (int j1 = list.size(); i1 < j1; ++i1)
{
VertexFormatElement vertexformatelement1 = list.get(i1);
VertexFormatElement.EnumUsage vertexformatelement$enumusage1 = vertexformatelement1.getUsage();
int k1 = vertexformatelement1.getIndex();
// moved to VertexFormatElement.postDraw
vertexformatelement1.getUsage().postDraw(vertexformat, i1, i, bytebuffer);
}
}
bufferBuilderIn.reset();
}
}

View File

@@ -0,0 +1,82 @@
package net.minecraft.client.renderer.block.model;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BakedQuad implements net.minecraftforge.client.model.pipeline.IVertexProducer
{
/**
* Joined 4 vertex records, each stores packed data according to the VertexFormat of the quad. Vanilla minecraft
* uses DefaultVertexFormats.BLOCK, Forge uses (usually) ITEM, use BakedQuad.getFormat() to get the correct format.
*/
protected final int[] vertexData;
protected final int tintIndex;
protected final EnumFacing face;
protected final TextureAtlasSprite sprite;
/**
* @deprecated Use constructor with the format argument.
*/
@Deprecated
public BakedQuad(int[] vertexDataIn, int tintIndexIn, EnumFacing faceIn, TextureAtlasSprite spriteIn)
{
this(vertexDataIn, tintIndexIn, faceIn, spriteIn, true, net.minecraft.client.renderer.vertex.DefaultVertexFormats.ITEM);
}
public BakedQuad(int[] vertexDataIn, int tintIndexIn, EnumFacing faceIn, TextureAtlasSprite spriteIn, boolean applyDiffuseLighting, net.minecraft.client.renderer.vertex.VertexFormat format)
{
this.format = format;
this.applyDiffuseLighting = applyDiffuseLighting;
this.vertexData = vertexDataIn;
this.tintIndex = tintIndexIn;
this.face = faceIn;
this.sprite = spriteIn;
}
public TextureAtlasSprite getSprite()
{
return this.sprite;
}
public int[] getVertexData()
{
return this.vertexData;
}
public boolean hasTintIndex()
{
return this.tintIndex != -1;
}
public int getTintIndex()
{
return this.tintIndex;
}
public EnumFacing getFace()
{
return this.face;
}
protected final net.minecraft.client.renderer.vertex.VertexFormat format;
protected final boolean applyDiffuseLighting;
@Override
public void pipe(net.minecraftforge.client.model.pipeline.IVertexConsumer consumer)
{
net.minecraftforge.client.model.pipeline.LightUtil.putBakedQuad(consumer, this);
}
public net.minecraft.client.renderer.vertex.VertexFormat getFormat()
{
return format;
}
public boolean shouldApplyDiffuseLighting()
{
return applyDiffuseLighting;
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.client.renderer.block.model;
import java.util.Arrays;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BakedQuadRetextured extends BakedQuad
{
private final TextureAtlasSprite texture;
public BakedQuadRetextured(BakedQuad quad, TextureAtlasSprite textureIn)
{
super(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), quad.tintIndex, FaceBakery.getFacingFromVertexData(quad.getVertexData()), quad.getSprite(), quad.applyDiffuseLighting, quad.format);
this.texture = textureIn;
this.remapQuad();
}
private void remapQuad()
{
for (int i = 0; i < 4; ++i)
{
int j = format.getIntegerSize() * i;
int uvIndex = format.getUvOffsetById(0) / 4;
this.vertexData[j + uvIndex] = Float.floatToRawIntBits(this.texture.getInterpolatedU((double)this.sprite.getUnInterpolatedU(Float.intBitsToFloat(this.vertexData[j + uvIndex]))));
this.vertexData[j + uvIndex + 1] = Float.floatToRawIntBits(this.texture.getInterpolatedV((double)this.sprite.getUnInterpolatedV(Float.intBitsToFloat(this.vertexData[j + uvIndex + 1]))));
}
}
@Override
public TextureAtlasSprite getSprite()
{
return texture;
}
}

View File

@@ -0,0 +1,125 @@
package net.minecraft.client.renderer.block.model;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import javax.annotation.Nullable;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BlockFaceUV
{
public float[] uvs;
public final int rotation;
public BlockFaceUV(@Nullable float[] uvsIn, int rotationIn)
{
this.uvs = uvsIn;
this.rotation = rotationIn;
}
public float getVertexU(int p_178348_1_)
{
if (this.uvs == null)
{
throw new NullPointerException("uvs");
}
else
{
int i = this.getVertexRotated(p_178348_1_);
return i != 0 && i != 1 ? this.uvs[2] : this.uvs[0];
}
}
public float getVertexV(int p_178346_1_)
{
if (this.uvs == null)
{
throw new NullPointerException("uvs");
}
else
{
int i = this.getVertexRotated(p_178346_1_);
return i != 0 && i != 3 ? this.uvs[3] : this.uvs[1];
}
}
private int getVertexRotated(int p_178347_1_)
{
return (p_178347_1_ + this.rotation / 90) % 4;
}
public int getVertexRotatedRev(int p_178345_1_)
{
return (p_178345_1_ + (4 - this.rotation / 90)) % 4;
}
public void setUvs(float[] uvsIn)
{
if (this.uvs == null)
{
this.uvs = uvsIn;
}
}
@SideOnly(Side.CLIENT)
static class Deserializer implements JsonDeserializer<BlockFaceUV>
{
public BlockFaceUV deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
float[] afloat = this.parseUV(jsonobject);
int i = this.parseRotation(jsonobject);
return new BlockFaceUV(afloat, i);
}
protected int parseRotation(JsonObject object)
{
int i = JsonUtils.getInt(object, "rotation", 0);
if (i >= 0 && i % 90 == 0 && i / 90 <= 3)
{
return i;
}
else
{
throw new JsonParseException("Invalid rotation " + i + " found, only 0/90/180/270 allowed");
}
}
@Nullable
private float[] parseUV(JsonObject object)
{
if (!object.has("uv"))
{
return null;
}
else
{
JsonArray jsonarray = JsonUtils.getJsonArray(object, "uv");
if (jsonarray.size() != 4)
{
throw new JsonParseException("Expected 4 uv values, found: " + jsonarray.size());
}
else
{
float[] afloat = new float[4];
for (int i = 0; i < afloat.length; ++i)
{
afloat[i] = JsonUtils.getFloat(jsonarray.get(i), "uv[" + i + "]");
}
return afloat;
}
}
}
}
}

View File

@@ -0,0 +1,231 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.collect.Maps;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
@SideOnly(Side.CLIENT)
public class BlockPart
{
public final Vector3f positionFrom;
public final Vector3f positionTo;
public final Map<EnumFacing, BlockPartFace> mapFaces;
public final BlockPartRotation partRotation;
public final boolean shade;
public BlockPart(Vector3f positionFromIn, Vector3f positionToIn, Map<EnumFacing, BlockPartFace> mapFacesIn, @Nullable BlockPartRotation partRotationIn, boolean shadeIn)
{
this.positionFrom = positionFromIn;
this.positionTo = positionToIn;
this.mapFaces = mapFacesIn;
this.partRotation = partRotationIn;
this.shade = shadeIn;
this.setDefaultUvs();
}
private void setDefaultUvs()
{
for (Entry<EnumFacing, BlockPartFace> entry : this.mapFaces.entrySet())
{
float[] afloat = this.getFaceUvs(entry.getKey());
(entry.getValue()).blockFaceUV.setUvs(afloat);
}
}
private float[] getFaceUvs(EnumFacing facing)
{
switch (facing)
{
case DOWN:
return new float[] {this.positionFrom.x, 16.0F - this.positionTo.z, this.positionTo.x, 16.0F - this.positionFrom.z};
case UP:
return new float[] {this.positionFrom.x, this.positionFrom.z, this.positionTo.x, this.positionTo.z};
case NORTH:
default:
return new float[] {16.0F - this.positionTo.x, 16.0F - this.positionTo.y, 16.0F - this.positionFrom.x, 16.0F - this.positionFrom.y};
case SOUTH:
return new float[] {this.positionFrom.x, 16.0F - this.positionTo.y, this.positionTo.x, 16.0F - this.positionFrom.y};
case WEST:
return new float[] {this.positionFrom.z, 16.0F - this.positionTo.y, this.positionTo.z, 16.0F - this.positionFrom.y};
case EAST:
return new float[] {16.0F - this.positionTo.z, 16.0F - this.positionTo.y, 16.0F - this.positionFrom.z, 16.0F - this.positionFrom.y};
}
}
@SideOnly(Side.CLIENT)
static class Deserializer implements JsonDeserializer<BlockPart>
{
public BlockPart deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
Vector3f vector3f = this.parsePositionFrom(jsonobject);
Vector3f vector3f1 = this.parsePositionTo(jsonobject);
BlockPartRotation blockpartrotation = this.parseRotation(jsonobject);
Map<EnumFacing, BlockPartFace> map = this.parseFacesCheck(p_deserialize_3_, jsonobject);
if (jsonobject.has("shade") && !JsonUtils.isBoolean(jsonobject, "shade"))
{
throw new JsonParseException("Expected shade to be a Boolean");
}
else
{
boolean flag = JsonUtils.getBoolean(jsonobject, "shade", true);
return new BlockPart(vector3f, vector3f1, map, blockpartrotation, flag);
}
}
@Nullable
private BlockPartRotation parseRotation(JsonObject object)
{
BlockPartRotation blockpartrotation = null;
if (object.has("rotation"))
{
JsonObject jsonobject = JsonUtils.getJsonObject(object, "rotation");
Vector3f vector3f = this.parsePosition(jsonobject, "origin");
vector3f.scale(0.0625F);
EnumFacing.Axis enumfacing$axis = this.parseAxis(jsonobject);
float f = this.parseAngle(jsonobject);
boolean flag = JsonUtils.getBoolean(jsonobject, "rescale", false);
blockpartrotation = new BlockPartRotation(vector3f, enumfacing$axis, f, flag);
}
return blockpartrotation;
}
private float parseAngle(JsonObject object)
{
float f = JsonUtils.getFloat(object, "angle");
if (f != 0.0F && MathHelper.abs(f) != 22.5F && MathHelper.abs(f) != 45.0F)
{
throw new JsonParseException("Invalid rotation " + f + " found, only -45/-22.5/0/22.5/45 allowed");
}
else
{
return f;
}
}
private EnumFacing.Axis parseAxis(JsonObject object)
{
String s = JsonUtils.getString(object, "axis");
EnumFacing.Axis enumfacing$axis = EnumFacing.Axis.byName(s.toLowerCase(Locale.ROOT));
if (enumfacing$axis == null)
{
throw new JsonParseException("Invalid rotation axis: " + s);
}
else
{
return enumfacing$axis;
}
}
private Map<EnumFacing, BlockPartFace> parseFacesCheck(JsonDeserializationContext deserializationContext, JsonObject object)
{
Map<EnumFacing, BlockPartFace> map = this.parseFaces(deserializationContext, object);
if (map.isEmpty())
{
throw new JsonParseException("Expected between 1 and 6 unique faces, got 0");
}
else
{
return map;
}
}
private Map<EnumFacing, BlockPartFace> parseFaces(JsonDeserializationContext deserializationContext, JsonObject object)
{
Map<EnumFacing, BlockPartFace> map = Maps.newEnumMap(EnumFacing.class);
JsonObject jsonobject = JsonUtils.getJsonObject(object, "faces");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
EnumFacing enumfacing = this.parseEnumFacing(entry.getKey());
map.put(enumfacing, (BlockPartFace)deserializationContext.deserialize(entry.getValue(), BlockPartFace.class));
}
return map;
}
private EnumFacing parseEnumFacing(String name)
{
EnumFacing enumfacing = EnumFacing.byName(name);
if (enumfacing == null)
{
throw new JsonParseException("Unknown facing: " + name);
}
else
{
return enumfacing;
}
}
private Vector3f parsePositionTo(JsonObject object)
{
Vector3f vector3f = this.parsePosition(object, "to");
if (vector3f.x >= -16.0F && vector3f.y >= -16.0F && vector3f.z >= -16.0F && vector3f.x <= 32.0F && vector3f.y <= 32.0F && vector3f.z <= 32.0F)
{
return vector3f;
}
else
{
throw new JsonParseException("'to' specifier exceeds the allowed boundaries: " + vector3f);
}
}
private Vector3f parsePositionFrom(JsonObject object)
{
Vector3f vector3f = this.parsePosition(object, "from");
if (vector3f.x >= -16.0F && vector3f.y >= -16.0F && vector3f.z >= -16.0F && vector3f.x <= 32.0F && vector3f.y <= 32.0F && vector3f.z <= 32.0F)
{
return vector3f;
}
else
{
throw new JsonParseException("'from' specifier exceeds the allowed boundaries: " + vector3f);
}
}
private Vector3f parsePosition(JsonObject object, String memberName)
{
JsonArray jsonarray = JsonUtils.getJsonArray(object, memberName);
if (jsonarray.size() != 3)
{
throw new JsonParseException("Expected 3 " + memberName + " values, found: " + jsonarray.size());
}
else
{
float[] afloat = new float[3];
for (int i = 0; i < afloat.length; ++i)
{
afloat[i] = JsonUtils.getFloat(jsonarray.get(i), memberName + "[" + i + "]");
}
return new Vector3f(afloat[0], afloat[1], afloat[2]);
}
}
}
}

View File

@@ -0,0 +1,62 @@
package net.minecraft.client.renderer.block.model;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import javax.annotation.Nullable;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BlockPartFace
{
public static final EnumFacing FACING_DEFAULT = null;
public final EnumFacing cullFace;
public final int tintIndex;
public final String texture;
public final BlockFaceUV blockFaceUV;
public BlockPartFace(@Nullable EnumFacing cullFaceIn, int tintIndexIn, String textureIn, BlockFaceUV blockFaceUVIn)
{
this.cullFace = cullFaceIn;
this.tintIndex = tintIndexIn;
this.texture = textureIn;
this.blockFaceUV = blockFaceUVIn;
}
@SideOnly(Side.CLIENT)
static class Deserializer implements JsonDeserializer<BlockPartFace>
{
public BlockPartFace deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
EnumFacing enumfacing = this.parseCullFace(jsonobject);
int i = this.parseTintIndex(jsonobject);
String s = this.parseTexture(jsonobject);
BlockFaceUV blockfaceuv = (BlockFaceUV)p_deserialize_3_.deserialize(jsonobject, BlockFaceUV.class);
return new BlockPartFace(enumfacing, i, s, blockfaceuv);
}
protected int parseTintIndex(JsonObject object)
{
return JsonUtils.getInt(object, "tintindex", -1);
}
private String parseTexture(JsonObject object)
{
return JsonUtils.getString(object, "texture");
}
@Nullable
private EnumFacing parseCullFace(JsonObject object)
{
String s = JsonUtils.getString(object, "cullface", "");
return EnumFacing.byName(s);
}
}
}

View File

@@ -0,0 +1,23 @@
package net.minecraft.client.renderer.block.model;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
@SideOnly(Side.CLIENT)
public class BlockPartRotation
{
public final Vector3f origin;
public final EnumFacing.Axis axis;
public final float angle;
public final boolean rescale;
public BlockPartRotation(Vector3f originIn, EnumFacing.Axis axisIn, float angleIn, boolean rescaleIn)
{
this.origin = originIn;
this.axis = axisIn;
this.angle = angleIn;
this.rescale = rescaleIn;
}
}

View File

@@ -0,0 +1,58 @@
package net.minecraft.client.renderer.block.model;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BuiltInModel implements IBakedModel
{
private final ItemCameraTransforms cameraTransforms;
private final ItemOverrideList overrideList;
public BuiltInModel(ItemCameraTransforms p_i46537_1_, ItemOverrideList p_i46537_2_)
{
this.cameraTransforms = p_i46537_1_;
this.overrideList = p_i46537_2_;
}
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
return Collections.<BakedQuad>emptyList();
}
public boolean isAmbientOcclusion()
{
return false;
}
public boolean isGui3d()
{
return true;
}
public boolean isBuiltInRenderer()
{
return true;
}
public TextureAtlasSprite getParticleTexture()
{
return null;
}
public ItemCameraTransforms getItemCameraTransforms()
{
return this.cameraTransforms;
}
public ItemOverrideList getOverrides()
{
return this.overrideList;
}
}

View File

@@ -0,0 +1,490 @@
package net.minecraft.client.renderer.block.model;
import javax.annotation.Nullable;
import net.minecraft.client.renderer.EnumFaceDirection;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3i;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;
@SideOnly(Side.CLIENT)
public class FaceBakery
{
private static final float SCALE_ROTATION_22_5 = 1.0F / (float)Math.cos(0.39269909262657166D) - 1.0F;
private static final float SCALE_ROTATION_GENERAL = 1.0F / (float)Math.cos((Math.PI / 4D)) - 1.0F;
private static final FaceBakery.Rotation[] UV_ROTATIONS = new FaceBakery.Rotation[ModelRotation.values().length * EnumFacing.values().length];
private static final FaceBakery.Rotation UV_ROTATION_0 = new FaceBakery.Rotation()
{
BlockFaceUV makeRotatedUV(float p_188007_1_, float p_188007_2_, float p_188007_3_, float p_188007_4_)
{
return new BlockFaceUV(new float[] {p_188007_1_, p_188007_2_, p_188007_3_, p_188007_4_}, 0);
}
};
private static final FaceBakery.Rotation UV_ROTATION_270 = new FaceBakery.Rotation()
{
BlockFaceUV makeRotatedUV(float p_188007_1_, float p_188007_2_, float p_188007_3_, float p_188007_4_)
{
return new BlockFaceUV(new float[] {p_188007_4_, 16.0F - p_188007_1_, p_188007_2_, 16.0F - p_188007_3_}, 270);
}
};
private static final FaceBakery.Rotation UV_ROTATION_INVERSE = new FaceBakery.Rotation()
{
BlockFaceUV makeRotatedUV(float p_188007_1_, float p_188007_2_, float p_188007_3_, float p_188007_4_)
{
return new BlockFaceUV(new float[] {16.0F - p_188007_1_, 16.0F - p_188007_2_, 16.0F - p_188007_3_, 16.0F - p_188007_4_}, 0);
}
};
private static final FaceBakery.Rotation UV_ROTATION_90 = new FaceBakery.Rotation()
{
BlockFaceUV makeRotatedUV(float p_188007_1_, float p_188007_2_, float p_188007_3_, float p_188007_4_)
{
return new BlockFaceUV(new float[] {16.0F - p_188007_2_, p_188007_3_, 16.0F - p_188007_4_, p_188007_1_}, 90);
}
};
public BakedQuad makeBakedQuad(Vector3f posFrom, Vector3f posTo, BlockPartFace face, TextureAtlasSprite sprite, EnumFacing facing, ModelRotation modelRotationIn, @Nullable BlockPartRotation partRotation, boolean uvLocked, boolean shade)
{
return makeBakedQuad(posFrom, posTo, face, sprite, facing, (net.minecraftforge.common.model.ITransformation)modelRotationIn, partRotation, uvLocked, shade);
}
public BakedQuad makeBakedQuad(Vector3f posFrom, Vector3f posTo, BlockPartFace face, TextureAtlasSprite sprite, EnumFacing facing, net.minecraftforge.common.model.ITransformation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade)
{
BlockFaceUV blockfaceuv = face.blockFaceUV;
if (uvLocked)
{
blockfaceuv = net.minecraftforge.client.ForgeHooksClient.applyUVLock(face.blockFaceUV, facing, modelRotationIn);
}
int[] aint = this.makeQuadVertexData(blockfaceuv, sprite, facing, this.getPositionsDiv16(posFrom, posTo), modelRotationIn, partRotation, false);
EnumFacing enumfacing = getFacingFromVertexData(aint);
if (partRotation == null)
{
this.applyFacing(aint, enumfacing);
}
net.minecraftforge.client.ForgeHooksClient.fillNormal(aint, enumfacing);
return new BakedQuad(aint, face.tintIndex, enumfacing, sprite, shade, net.minecraft.client.renderer.vertex.DefaultVertexFormats.ITEM);
}
private BlockFaceUV applyUVLock(BlockFaceUV p_188010_1_, EnumFacing p_188010_2_, ModelRotation p_188010_3_)
{
return UV_ROTATIONS[getIndex(p_188010_3_, p_188010_2_)].rotateUV(p_188010_1_);
}
private int[] makeQuadVertexData(BlockFaceUV uvs, TextureAtlasSprite sprite, EnumFacing orientation, float[] p_188012_4_, ModelRotation rotationIn, @Nullable BlockPartRotation partRotation, boolean shade)
{
return makeQuadVertexData(uvs, sprite, orientation, p_188012_4_, (net.minecraftforge.common.model.ITransformation)rotationIn, partRotation, shade);
}
private int[] makeQuadVertexData(BlockFaceUV uvs, TextureAtlasSprite sprite, EnumFacing orientation, float[] p_188012_4_, net.minecraftforge.common.model.ITransformation rotationIn, BlockPartRotation partRotation, boolean shade)
{
int[] aint = new int[28];
for (int i = 0; i < 4; ++i)
{
this.fillVertexData(aint, i, orientation, uvs, p_188012_4_, sprite, rotationIn, partRotation, shade);
}
return aint;
}
private int getFaceShadeColor(EnumFacing facing)
{
float f = this.getFaceBrightness(facing);
int i = MathHelper.clamp((int)(f * 255.0F), 0, 255);
return -16777216 | i << 16 | i << 8 | i;
}
private float getFaceBrightness(EnumFacing facing)
{
switch (facing)
{
case DOWN:
return 0.5F;
case UP:
return 1.0F;
case NORTH:
case SOUTH:
return 0.8F;
case WEST:
case EAST:
return 0.6F;
default:
return 1.0F;
}
}
private float[] getPositionsDiv16(Vector3f pos1, Vector3f pos2)
{
float[] afloat = new float[EnumFacing.values().length];
afloat[EnumFaceDirection.Constants.WEST_INDEX] = pos1.x / 16.0F;
afloat[EnumFaceDirection.Constants.DOWN_INDEX] = pos1.y / 16.0F;
afloat[EnumFaceDirection.Constants.NORTH_INDEX] = pos1.z / 16.0F;
afloat[EnumFaceDirection.Constants.EAST_INDEX] = pos2.x / 16.0F;
afloat[EnumFaceDirection.Constants.UP_INDEX] = pos2.y / 16.0F;
afloat[EnumFaceDirection.Constants.SOUTH_INDEX] = pos2.z / 16.0F;
return afloat;
}
private void fillVertexData(int[] p_188015_1_, int p_188015_2_, EnumFacing p_188015_3_, BlockFaceUV p_188015_4_, float[] p_188015_5_, TextureAtlasSprite p_188015_6_, ModelRotation p_188015_7_, @Nullable BlockPartRotation p_188015_8_, boolean p_188015_9_)
{
fillVertexData(p_188015_1_, p_188015_2_, p_188015_3_, p_188015_4_, p_188015_5_, p_188015_6_, (net.minecraftforge.common.model.ITransformation)p_188015_7_, p_188015_8_, p_188015_9_);
}
private void fillVertexData(int[] p_188015_1_, int p_188015_2_, EnumFacing p_188015_3_, BlockFaceUV p_188015_4_, float[] p_188015_5_, TextureAtlasSprite p_188015_6_, net.minecraftforge.common.model.ITransformation p_188015_7_, BlockPartRotation p_188015_8_, boolean p_188015_9_)
{
EnumFacing enumfacing = p_188015_7_.rotate(p_188015_3_);
int i = p_188015_9_ ? this.getFaceShadeColor(enumfacing) : -1;
EnumFaceDirection.VertexInformation enumfacedirection$vertexinformation = EnumFaceDirection.getFacing(p_188015_3_).getVertexInformation(p_188015_2_);
Vector3f vector3f = new Vector3f(p_188015_5_[enumfacedirection$vertexinformation.xIndex], p_188015_5_[enumfacedirection$vertexinformation.yIndex], p_188015_5_[enumfacedirection$vertexinformation.zIndex]);
this.rotatePart(vector3f, p_188015_8_);
int j = this.rotateVertex(vector3f, p_188015_3_, p_188015_2_, p_188015_7_);
this.storeVertexData(p_188015_1_, j, p_188015_2_, vector3f, i, p_188015_6_, p_188015_4_);
}
private void storeVertexData(int[] faceData, int storeIndex, int vertexIndex, Vector3f position, int shadeColor, TextureAtlasSprite sprite, BlockFaceUV faceUV)
{
int i = storeIndex * 7;
faceData[i] = Float.floatToRawIntBits(position.x);
faceData[i + 1] = Float.floatToRawIntBits(position.y);
faceData[i + 2] = Float.floatToRawIntBits(position.z);
faceData[i + 3] = shadeColor;
faceData[i + 4] = Float.floatToRawIntBits(sprite.getInterpolatedU((double)faceUV.getVertexU(vertexIndex) * .999 + faceUV.getVertexU((vertexIndex + 2) % 4) * .001));
faceData[i + 4 + 1] = Float.floatToRawIntBits(sprite.getInterpolatedV((double)faceUV.getVertexV(vertexIndex) * .999 + faceUV.getVertexV((vertexIndex + 2) % 4) * .001));
}
private void rotatePart(Vector3f p_178407_1_, @Nullable BlockPartRotation partRotation)
{
if (partRotation != null)
{
Matrix4f matrix4f = this.getMatrixIdentity();
Vector3f vector3f = new Vector3f(0.0F, 0.0F, 0.0F);
switch (partRotation.axis)
{
case X:
Matrix4f.rotate(partRotation.angle * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), matrix4f, matrix4f);
vector3f.set(0.0F, 1.0F, 1.0F);
break;
case Y:
Matrix4f.rotate(partRotation.angle * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), matrix4f, matrix4f);
vector3f.set(1.0F, 0.0F, 1.0F);
break;
case Z:
Matrix4f.rotate(partRotation.angle * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), matrix4f, matrix4f);
vector3f.set(1.0F, 1.0F, 0.0F);
}
if (partRotation.rescale)
{
if (Math.abs(partRotation.angle) == 22.5F)
{
vector3f.scale(SCALE_ROTATION_22_5);
}
else
{
vector3f.scale(SCALE_ROTATION_GENERAL);
}
Vector3f.add(vector3f, new Vector3f(1.0F, 1.0F, 1.0F), vector3f);
}
else
{
vector3f.set(1.0F, 1.0F, 1.0F);
}
this.rotateScale(p_178407_1_, new Vector3f(partRotation.origin), matrix4f, vector3f);
}
}
public int rotateVertex(Vector3f p_188011_1_, EnumFacing p_188011_2_, int p_188011_3_, ModelRotation p_188011_4_)
{
return rotateVertex(p_188011_1_, p_188011_2_, p_188011_3_, (net.minecraftforge.common.model.ITransformation)p_188011_4_);
}
public int rotateVertex(Vector3f p_188011_1_, EnumFacing p_188011_2_, int p_188011_3_, net.minecraftforge.common.model.ITransformation p_188011_4_)
{
if (p_188011_4_ == ModelRotation.X0_Y0)
{
return p_188011_3_;
}
else
{
net.minecraftforge.client.ForgeHooksClient.transform(p_188011_1_, p_188011_4_.getMatrix());
return p_188011_4_.rotate(p_188011_2_, p_188011_3_);
}
}
private void rotateScale(Vector3f position, Vector3f rotationOrigin, Matrix4f rotationMatrix, Vector3f scale)
{
Vector4f vector4f = new Vector4f(position.x - rotationOrigin.x, position.y - rotationOrigin.y, position.z - rotationOrigin.z, 1.0F);
Matrix4f.transform(rotationMatrix, vector4f, vector4f);
vector4f.x *= scale.x;
vector4f.y *= scale.y;
vector4f.z *= scale.z;
position.set(vector4f.x + rotationOrigin.x, vector4f.y + rotationOrigin.y, vector4f.z + rotationOrigin.z);
}
private Matrix4f getMatrixIdentity()
{
Matrix4f matrix4f = new Matrix4f();
matrix4f.setIdentity();
return matrix4f;
}
public static EnumFacing getFacingFromVertexData(int[] faceData)
{
Vector3f vector3f = new Vector3f(Float.intBitsToFloat(faceData[0]), Float.intBitsToFloat(faceData[1]), Float.intBitsToFloat(faceData[2]));
Vector3f vector3f1 = new Vector3f(Float.intBitsToFloat(faceData[7]), Float.intBitsToFloat(faceData[8]), Float.intBitsToFloat(faceData[9]));
Vector3f vector3f2 = new Vector3f(Float.intBitsToFloat(faceData[14]), Float.intBitsToFloat(faceData[15]), Float.intBitsToFloat(faceData[16]));
Vector3f vector3f3 = new Vector3f();
Vector3f vector3f4 = new Vector3f();
Vector3f vector3f5 = new Vector3f();
Vector3f.sub(vector3f, vector3f1, vector3f3);
Vector3f.sub(vector3f2, vector3f1, vector3f4);
Vector3f.cross(vector3f4, vector3f3, vector3f5);
float f = (float)Math.sqrt((double)(vector3f5.x * vector3f5.x + vector3f5.y * vector3f5.y + vector3f5.z * vector3f5.z));
vector3f5.x /= f;
vector3f5.y /= f;
vector3f5.z /= f;
EnumFacing enumfacing = null;
float f1 = 0.0F;
for (EnumFacing enumfacing1 : EnumFacing.values())
{
Vec3i vec3i = enumfacing1.getDirectionVec();
Vector3f vector3f6 = new Vector3f((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ());
float f2 = Vector3f.dot(vector3f5, vector3f6);
if (f2 >= 0.0F && f2 > f1)
{
f1 = f2;
enumfacing = enumfacing1;
}
}
if (enumfacing == null)
{
return EnumFacing.UP;
}
else
{
return enumfacing;
}
}
private void applyFacing(int[] p_178408_1_, EnumFacing p_178408_2_)
{
int[] aint = new int[p_178408_1_.length];
System.arraycopy(p_178408_1_, 0, aint, 0, p_178408_1_.length);
float[] afloat = new float[EnumFacing.values().length];
afloat[EnumFaceDirection.Constants.WEST_INDEX] = 999.0F;
afloat[EnumFaceDirection.Constants.DOWN_INDEX] = 999.0F;
afloat[EnumFaceDirection.Constants.NORTH_INDEX] = 999.0F;
afloat[EnumFaceDirection.Constants.EAST_INDEX] = -999.0F;
afloat[EnumFaceDirection.Constants.UP_INDEX] = -999.0F;
afloat[EnumFaceDirection.Constants.SOUTH_INDEX] = -999.0F;
for (int i = 0; i < 4; ++i)
{
int j = 7 * i;
float f = Float.intBitsToFloat(aint[j]);
float f1 = Float.intBitsToFloat(aint[j + 1]);
float f2 = Float.intBitsToFloat(aint[j + 2]);
if (f < afloat[EnumFaceDirection.Constants.WEST_INDEX])
{
afloat[EnumFaceDirection.Constants.WEST_INDEX] = f;
}
if (f1 < afloat[EnumFaceDirection.Constants.DOWN_INDEX])
{
afloat[EnumFaceDirection.Constants.DOWN_INDEX] = f1;
}
if (f2 < afloat[EnumFaceDirection.Constants.NORTH_INDEX])
{
afloat[EnumFaceDirection.Constants.NORTH_INDEX] = f2;
}
if (f > afloat[EnumFaceDirection.Constants.EAST_INDEX])
{
afloat[EnumFaceDirection.Constants.EAST_INDEX] = f;
}
if (f1 > afloat[EnumFaceDirection.Constants.UP_INDEX])
{
afloat[EnumFaceDirection.Constants.UP_INDEX] = f1;
}
if (f2 > afloat[EnumFaceDirection.Constants.SOUTH_INDEX])
{
afloat[EnumFaceDirection.Constants.SOUTH_INDEX] = f2;
}
}
EnumFaceDirection enumfacedirection = EnumFaceDirection.getFacing(p_178408_2_);
for (int i1 = 0; i1 < 4; ++i1)
{
int j1 = 7 * i1;
EnumFaceDirection.VertexInformation enumfacedirection$vertexinformation = enumfacedirection.getVertexInformation(i1);
float f8 = afloat[enumfacedirection$vertexinformation.xIndex];
float f3 = afloat[enumfacedirection$vertexinformation.yIndex];
float f4 = afloat[enumfacedirection$vertexinformation.zIndex];
p_178408_1_[j1] = Float.floatToRawIntBits(f8);
p_178408_1_[j1 + 1] = Float.floatToRawIntBits(f3);
p_178408_1_[j1 + 2] = Float.floatToRawIntBits(f4);
for (int k = 0; k < 4; ++k)
{
int l = 7 * k;
float f5 = Float.intBitsToFloat(aint[l]);
float f6 = Float.intBitsToFloat(aint[l + 1]);
float f7 = Float.intBitsToFloat(aint[l + 2]);
if (MathHelper.epsilonEquals(f8, f5) && MathHelper.epsilonEquals(f3, f6) && MathHelper.epsilonEquals(f4, f7))
{
p_178408_1_[j1 + 4] = aint[l + 4];
p_178408_1_[j1 + 4 + 1] = aint[l + 4 + 1];
}
}
}
}
private static void addUvRotation(ModelRotation p_188013_0_, EnumFacing p_188013_1_, FaceBakery.Rotation p_188013_2_)
{
UV_ROTATIONS[getIndex(p_188013_0_, p_188013_1_)] = p_188013_2_;
}
private static int getIndex(ModelRotation p_188014_0_, EnumFacing p_188014_1_)
{
return ModelRotation.values().length * p_188014_1_.ordinal() + p_188014_0_.ordinal();
}
static
{
addUvRotation(ModelRotation.X0_Y0, EnumFacing.DOWN, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y0, EnumFacing.EAST, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y0, EnumFacing.NORTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y0, EnumFacing.SOUTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y0, EnumFacing.UP, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y0, EnumFacing.WEST, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y90, EnumFacing.EAST, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y90, EnumFacing.NORTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y90, EnumFacing.SOUTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y90, EnumFacing.WEST, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y180, EnumFacing.EAST, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y180, EnumFacing.NORTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y180, EnumFacing.SOUTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y180, EnumFacing.WEST, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y270, EnumFacing.EAST, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y270, EnumFacing.NORTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y270, EnumFacing.SOUTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y270, EnumFacing.WEST, UV_ROTATION_0);
addUvRotation(ModelRotation.X90_Y0, EnumFacing.DOWN, UV_ROTATION_0);
addUvRotation(ModelRotation.X90_Y0, EnumFacing.SOUTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X90_Y90, EnumFacing.DOWN, UV_ROTATION_0);
addUvRotation(ModelRotation.X90_Y180, EnumFacing.DOWN, UV_ROTATION_0);
addUvRotation(ModelRotation.X90_Y180, EnumFacing.NORTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X90_Y270, EnumFacing.DOWN, UV_ROTATION_0);
addUvRotation(ModelRotation.X180_Y0, EnumFacing.DOWN, UV_ROTATION_0);
addUvRotation(ModelRotation.X180_Y0, EnumFacing.UP, UV_ROTATION_0);
addUvRotation(ModelRotation.X270_Y0, EnumFacing.SOUTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X270_Y0, EnumFacing.UP, UV_ROTATION_0);
addUvRotation(ModelRotation.X270_Y90, EnumFacing.UP, UV_ROTATION_0);
addUvRotation(ModelRotation.X270_Y180, EnumFacing.NORTH, UV_ROTATION_0);
addUvRotation(ModelRotation.X270_Y180, EnumFacing.UP, UV_ROTATION_0);
addUvRotation(ModelRotation.X270_Y270, EnumFacing.UP, UV_ROTATION_0);
addUvRotation(ModelRotation.X0_Y270, EnumFacing.UP, UV_ROTATION_270);
addUvRotation(ModelRotation.X0_Y90, EnumFacing.DOWN, UV_ROTATION_270);
addUvRotation(ModelRotation.X90_Y0, EnumFacing.WEST, UV_ROTATION_270);
addUvRotation(ModelRotation.X90_Y90, EnumFacing.WEST, UV_ROTATION_270);
addUvRotation(ModelRotation.X90_Y180, EnumFacing.WEST, UV_ROTATION_270);
addUvRotation(ModelRotation.X90_Y270, EnumFacing.NORTH, UV_ROTATION_270);
addUvRotation(ModelRotation.X90_Y270, EnumFacing.SOUTH, UV_ROTATION_270);
addUvRotation(ModelRotation.X90_Y270, EnumFacing.WEST, UV_ROTATION_270);
addUvRotation(ModelRotation.X180_Y90, EnumFacing.UP, UV_ROTATION_270);
addUvRotation(ModelRotation.X180_Y270, EnumFacing.DOWN, UV_ROTATION_270);
addUvRotation(ModelRotation.X270_Y0, EnumFacing.EAST, UV_ROTATION_270);
addUvRotation(ModelRotation.X270_Y90, EnumFacing.EAST, UV_ROTATION_270);
addUvRotation(ModelRotation.X270_Y90, EnumFacing.NORTH, UV_ROTATION_270);
addUvRotation(ModelRotation.X270_Y90, EnumFacing.SOUTH, UV_ROTATION_270);
addUvRotation(ModelRotation.X270_Y180, EnumFacing.EAST, UV_ROTATION_270);
addUvRotation(ModelRotation.X270_Y270, EnumFacing.EAST, UV_ROTATION_270);
addUvRotation(ModelRotation.X0_Y180, EnumFacing.DOWN, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X0_Y180, EnumFacing.UP, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X90_Y0, EnumFacing.NORTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X90_Y0, EnumFacing.UP, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X90_Y90, EnumFacing.UP, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X90_Y180, EnumFacing.SOUTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X90_Y180, EnumFacing.UP, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X90_Y270, EnumFacing.UP, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y0, EnumFacing.EAST, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y0, EnumFacing.NORTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y0, EnumFacing.SOUTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y0, EnumFacing.WEST, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y90, EnumFacing.EAST, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y90, EnumFacing.NORTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y90, EnumFacing.SOUTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y90, EnumFacing.WEST, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y180, EnumFacing.DOWN, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y180, EnumFacing.EAST, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y180, EnumFacing.NORTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y180, EnumFacing.SOUTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y180, EnumFacing.UP, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y180, EnumFacing.WEST, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y270, EnumFacing.EAST, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y270, EnumFacing.NORTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y270, EnumFacing.SOUTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X180_Y270, EnumFacing.WEST, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X270_Y0, EnumFacing.DOWN, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X270_Y0, EnumFacing.NORTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X270_Y90, EnumFacing.DOWN, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X270_Y180, EnumFacing.DOWN, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X270_Y180, EnumFacing.SOUTH, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X270_Y270, EnumFacing.DOWN, UV_ROTATION_INVERSE);
addUvRotation(ModelRotation.X0_Y90, EnumFacing.UP, UV_ROTATION_90);
addUvRotation(ModelRotation.X0_Y270, EnumFacing.DOWN, UV_ROTATION_90);
addUvRotation(ModelRotation.X90_Y0, EnumFacing.EAST, UV_ROTATION_90);
addUvRotation(ModelRotation.X90_Y90, EnumFacing.EAST, UV_ROTATION_90);
addUvRotation(ModelRotation.X90_Y90, EnumFacing.NORTH, UV_ROTATION_90);
addUvRotation(ModelRotation.X90_Y90, EnumFacing.SOUTH, UV_ROTATION_90);
addUvRotation(ModelRotation.X90_Y180, EnumFacing.EAST, UV_ROTATION_90);
addUvRotation(ModelRotation.X90_Y270, EnumFacing.EAST, UV_ROTATION_90);
addUvRotation(ModelRotation.X270_Y0, EnumFacing.WEST, UV_ROTATION_90);
addUvRotation(ModelRotation.X180_Y90, EnumFacing.DOWN, UV_ROTATION_90);
addUvRotation(ModelRotation.X180_Y270, EnumFacing.UP, UV_ROTATION_90);
addUvRotation(ModelRotation.X270_Y90, EnumFacing.WEST, UV_ROTATION_90);
addUvRotation(ModelRotation.X270_Y180, EnumFacing.WEST, UV_ROTATION_90);
addUvRotation(ModelRotation.X270_Y270, EnumFacing.NORTH, UV_ROTATION_90);
addUvRotation(ModelRotation.X270_Y270, EnumFacing.SOUTH, UV_ROTATION_90);
addUvRotation(ModelRotation.X270_Y270, EnumFacing.WEST, UV_ROTATION_90);
}
@SideOnly(Side.CLIENT)
abstract static class Rotation
{
private Rotation()
{
}
public BlockFaceUV rotateUV(BlockFaceUV p_188006_1_)
{
float f = p_188006_1_.getVertexU(p_188006_1_.getVertexRotatedRev(0));
float f1 = p_188006_1_.getVertexV(p_188006_1_.getVertexRotatedRev(0));
float f2 = p_188006_1_.getVertexU(p_188006_1_.getVertexRotatedRev(2));
float f3 = p_188006_1_.getVertexV(p_188006_1_.getVertexRotatedRev(2));
return this.makeRotatedUV(f, f1, f2, f3);
}
abstract BlockFaceUV makeRotatedUV(float p_188007_1_, float p_188007_2_, float p_188007_3_, float p_188007_4_);
}
}

View File

@@ -0,0 +1,38 @@
package net.minecraft.client.renderer.block.model;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IBakedModel
{
List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand);
boolean isAmbientOcclusion();
boolean isGui3d();
boolean isBuiltInRenderer();
TextureAtlasSprite getParticleTexture();
@Deprecated
default ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
ItemOverrideList getOverrides();
default boolean isAmbientOcclusion(IBlockState state) { return isAmbientOcclusion(); }
/*
* Returns the pair of the model for the given perspective, and the matrix
* that should be applied to the GL state before rendering it (matrix may be null).
*/
default org.apache.commons.lang3.tuple.Pair<? extends IBakedModel, javax.vecmath.Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
return net.minecraftforge.client.ForgeHooksClient.handlePerspective(this, cameraTransformType);
}
}

View File

@@ -0,0 +1,190 @@
package net.minecraft.client.renderer.block.model;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Quaternion;
/*
* @deprecated use {@link net.minecraftforge.client.model.IPerspectiveAwareModel} instead
*/
@SideOnly(Side.CLIENT)
public class ItemCameraTransforms
{
public static final ItemCameraTransforms DEFAULT = new ItemCameraTransforms();
public static float offsetTranslateX;
public static float offsetTranslateY;
public static float offsetTranslateZ;
public static float offsetRotationX;
public static float offsetRotationY;
public static float offsetRotationZ;
public static float offsetScaleX;
public static float offsetScaleY;
public static float offsetScaleZ;
public final ItemTransformVec3f thirdperson_left;
public final ItemTransformVec3f thirdperson_right;
public final ItemTransformVec3f firstperson_left;
public final ItemTransformVec3f firstperson_right;
public final ItemTransformVec3f head;
public final ItemTransformVec3f gui;
public final ItemTransformVec3f ground;
public final ItemTransformVec3f fixed;
private ItemCameraTransforms()
{
this(ItemTransformVec3f.DEFAULT, ItemTransformVec3f.DEFAULT, ItemTransformVec3f.DEFAULT, ItemTransformVec3f.DEFAULT, ItemTransformVec3f.DEFAULT, ItemTransformVec3f.DEFAULT, ItemTransformVec3f.DEFAULT, ItemTransformVec3f.DEFAULT);
}
@Deprecated
public ItemCameraTransforms(ItemCameraTransforms transforms)
{
this.thirdperson_left = transforms.thirdperson_left;
this.thirdperson_right = transforms.thirdperson_right;
this.firstperson_left = transforms.firstperson_left;
this.firstperson_right = transforms.firstperson_right;
this.head = transforms.head;
this.gui = transforms.gui;
this.ground = transforms.ground;
this.fixed = transforms.fixed;
}
@Deprecated
public ItemCameraTransforms(ItemTransformVec3f thirdperson_leftIn, ItemTransformVec3f thirdperson_rightIn, ItemTransformVec3f firstperson_leftIn, ItemTransformVec3f firstperson_rightIn, ItemTransformVec3f headIn, ItemTransformVec3f guiIn, ItemTransformVec3f groundIn, ItemTransformVec3f fixedIn)
{
this.thirdperson_left = thirdperson_leftIn;
this.thirdperson_right = thirdperson_rightIn;
this.firstperson_left = firstperson_leftIn;
this.firstperson_right = firstperson_rightIn;
this.head = headIn;
this.gui = guiIn;
this.ground = groundIn;
this.fixed = fixedIn;
}
public void applyTransform(ItemCameraTransforms.TransformType type)
{
applyTransformSide(this.getTransform(type), false);
}
public static void applyTransformSide(ItemTransformVec3f vec, boolean leftHand)
{
if (vec != ItemTransformVec3f.DEFAULT)
{
int i = leftHand ? -1 : 1;
GlStateManager.translate((float)i * (offsetTranslateX + vec.translation.x), offsetTranslateY + vec.translation.y, offsetTranslateZ + vec.translation.z);
float f = offsetRotationX + vec.rotation.x;
float f1 = offsetRotationY + vec.rotation.y;
float f2 = offsetRotationZ + vec.rotation.z;
if (leftHand)
{
f1 = -f1;
f2 = -f2;
}
GlStateManager.rotate(makeQuaternion(f, f1, f2));
GlStateManager.scale(offsetScaleX + vec.scale.x, offsetScaleY + vec.scale.y, offsetScaleZ + vec.scale.z);
}
}
private static Quaternion makeQuaternion(float p_188035_0_, float p_188035_1_, float p_188035_2_)
{
float f = p_188035_0_ * 0.017453292F;
float f1 = p_188035_1_ * 0.017453292F;
float f2 = p_188035_2_ * 0.017453292F;
float f3 = MathHelper.sin(0.5F * f);
float f4 = MathHelper.cos(0.5F * f);
float f5 = MathHelper.sin(0.5F * f1);
float f6 = MathHelper.cos(0.5F * f1);
float f7 = MathHelper.sin(0.5F * f2);
float f8 = MathHelper.cos(0.5F * f2);
return new Quaternion(f3 * f6 * f8 + f4 * f5 * f7, f4 * f5 * f8 - f3 * f6 * f7, f3 * f5 * f8 + f4 * f6 * f7, f4 * f6 * f8 - f3 * f5 * f7);
}
@Deprecated
public ItemTransformVec3f getTransform(ItemCameraTransforms.TransformType type)
{
switch (type)
{
case THIRD_PERSON_LEFT_HAND:
return this.thirdperson_left;
case THIRD_PERSON_RIGHT_HAND:
return this.thirdperson_right;
case FIRST_PERSON_LEFT_HAND:
return this.firstperson_left;
case FIRST_PERSON_RIGHT_HAND:
return this.firstperson_right;
case HEAD:
return this.head;
case GUI:
return this.gui;
case GROUND:
return this.ground;
case FIXED:
return this.fixed;
default:
return ItemTransformVec3f.DEFAULT;
}
}
public boolean hasCustomTransform(ItemCameraTransforms.TransformType type)
{
return this.getTransform(type) != ItemTransformVec3f.DEFAULT;
}
@SideOnly(Side.CLIENT)
static class Deserializer implements JsonDeserializer<ItemCameraTransforms>
{
public ItemCameraTransforms deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
ItemTransformVec3f itemtransformvec3f = this.getTransform(p_deserialize_3_, jsonobject, "thirdperson_righthand");
ItemTransformVec3f itemtransformvec3f1 = this.getTransform(p_deserialize_3_, jsonobject, "thirdperson_lefthand");
if (itemtransformvec3f1 == ItemTransformVec3f.DEFAULT)
{
itemtransformvec3f1 = itemtransformvec3f;
}
ItemTransformVec3f itemtransformvec3f2 = this.getTransform(p_deserialize_3_, jsonobject, "firstperson_righthand");
ItemTransformVec3f itemtransformvec3f3 = this.getTransform(p_deserialize_3_, jsonobject, "firstperson_lefthand");
if (itemtransformvec3f3 == ItemTransformVec3f.DEFAULT)
{
itemtransformvec3f3 = itemtransformvec3f2;
}
ItemTransformVec3f itemtransformvec3f4 = this.getTransform(p_deserialize_3_, jsonobject, "head");
ItemTransformVec3f itemtransformvec3f5 = this.getTransform(p_deserialize_3_, jsonobject, "gui");
ItemTransformVec3f itemtransformvec3f6 = this.getTransform(p_deserialize_3_, jsonobject, "ground");
ItemTransformVec3f itemtransformvec3f7 = this.getTransform(p_deserialize_3_, jsonobject, "fixed");
return new ItemCameraTransforms(itemtransformvec3f1, itemtransformvec3f, itemtransformvec3f3, itemtransformvec3f2, itemtransformvec3f4, itemtransformvec3f5, itemtransformvec3f6, itemtransformvec3f7);
}
private ItemTransformVec3f getTransform(JsonDeserializationContext p_181683_1_, JsonObject p_181683_2_, String p_181683_3_)
{
return p_181683_2_.has(p_181683_3_) ? (ItemTransformVec3f)p_181683_1_.deserialize(p_181683_2_.get(p_181683_3_), ItemTransformVec3f.class) : ItemTransformVec3f.DEFAULT;
}
}
@SideOnly(Side.CLIENT)
public static enum TransformType implements net.minecraftforge.common.model.IModelPart
{
NONE,
THIRD_PERSON_LEFT_HAND,
THIRD_PERSON_RIGHT_HAND,
FIRST_PERSON_LEFT_HAND,
FIRST_PERSON_RIGHT_HAND,
HEAD,
GUI,
GROUND,
FIXED;
}
}

View File

@@ -0,0 +1,338 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
@SideOnly(Side.CLIENT)
public class ItemModelGenerator
{
public static final List<String> LAYERS = Lists.newArrayList("layer0", "layer1", "layer2", "layer3", "layer4");
@Nullable
public ModelBlock makeItemModel(TextureMap textureMapIn, ModelBlock blockModel)
{
Map<String, String> map = Maps.<String, String>newHashMap();
List<BlockPart> list = Lists.<BlockPart>newArrayList();
for (int i = 0; i < LAYERS.size(); ++i)
{
String s = LAYERS.get(i);
if (!blockModel.isTexturePresent(s))
{
break;
}
String s1 = blockModel.resolveTextureName(s);
map.put(s, s1);
TextureAtlasSprite textureatlassprite = textureMapIn.getAtlasSprite((new ResourceLocation(s1)).toString());
list.addAll(this.getBlockParts(i, s, textureatlassprite));
}
if (list.isEmpty())
{
return null;
}
else
{
map.put("particle", blockModel.isTexturePresent("particle") ? blockModel.resolveTextureName("particle") : (String)map.get("layer0"));
return new ModelBlock((ResourceLocation)null, list, map, false, false, blockModel.getAllTransforms(), blockModel.getOverrides());
}
}
private List<BlockPart> getBlockParts(int tintIndex, String p_178394_2_, TextureAtlasSprite p_178394_3_)
{
Map<EnumFacing, BlockPartFace> map = Maps.<EnumFacing, BlockPartFace>newHashMap();
map.put(EnumFacing.SOUTH, new BlockPartFace((EnumFacing)null, tintIndex, p_178394_2_, new BlockFaceUV(new float[] {0.0F, 0.0F, 16.0F, 16.0F}, 0)));
map.put(EnumFacing.NORTH, new BlockPartFace((EnumFacing)null, tintIndex, p_178394_2_, new BlockFaceUV(new float[] {16.0F, 0.0F, 0.0F, 16.0F}, 0)));
List<BlockPart> list = Lists.<BlockPart>newArrayList();
list.add(new BlockPart(new Vector3f(0.0F, 0.0F, 7.5F), new Vector3f(16.0F, 16.0F, 8.5F), map, (BlockPartRotation)null, true));
list.addAll(this.getBlockParts(p_178394_3_, p_178394_2_, tintIndex));
return list;
}
private List<BlockPart> getBlockParts(TextureAtlasSprite p_178397_1_, String p_178397_2_, int p_178397_3_)
{
float f = (float)p_178397_1_.getIconWidth();
float f1 = (float)p_178397_1_.getIconHeight();
List<BlockPart> list = Lists.<BlockPart>newArrayList();
for (ItemModelGenerator.Span itemmodelgenerator$span : this.getSpans(p_178397_1_))
{
float f2 = 0.0F;
float f3 = 0.0F;
float f4 = 0.0F;
float f5 = 0.0F;
float f6 = 0.0F;
float f7 = 0.0F;
float f8 = 0.0F;
float f9 = 0.0F;
float f10 = 0.0F;
float f11 = 0.0F;
float f12 = (float)itemmodelgenerator$span.getMin();
float f13 = (float)itemmodelgenerator$span.getMax();
float f14 = (float)itemmodelgenerator$span.getAnchor();
ItemModelGenerator.SpanFacing itemmodelgenerator$spanfacing = itemmodelgenerator$span.getFacing();
switch (itemmodelgenerator$spanfacing)
{
case UP:
f6 = f12;
f2 = f12;
f4 = f7 = f13 + 1.0F;
f8 = f14;
f3 = f14;
f9 = f14;
f5 = f14;
f10 = 16.0F / f;
f11 = 16.0F / (f1 - 1.0F);
break;
case DOWN:
f9 = f14;
f8 = f14;
f6 = f12;
f2 = f12;
f4 = f7 = f13 + 1.0F;
f3 = f14 + 1.0F;
f5 = f14 + 1.0F;
f10 = 16.0F / f;
f11 = 16.0F / (f1 - 1.0F);
break;
case LEFT:
f6 = f14;
f2 = f14;
f7 = f14;
f4 = f14;
f9 = f12;
f3 = f12;
f5 = f8 = f13 + 1.0F;
f10 = 16.0F / (f - 1.0F);
f11 = 16.0F / f1;
break;
case RIGHT:
f7 = f14;
f6 = f14;
f2 = f14 + 1.0F;
f4 = f14 + 1.0F;
f9 = f12;
f3 = f12;
f5 = f8 = f13 + 1.0F;
f10 = 16.0F / (f - 1.0F);
f11 = 16.0F / f1;
}
float f15 = 16.0F / f;
float f16 = 16.0F / f1;
f2 = f2 * f15;
f4 = f4 * f15;
f3 = f3 * f16;
f5 = f5 * f16;
f3 = 16.0F - f3;
f5 = 16.0F - f5;
f6 = f6 * f10;
f7 = f7 * f10;
f8 = f8 * f11;
f9 = f9 * f11;
Map<EnumFacing, BlockPartFace> map = Maps.<EnumFacing, BlockPartFace>newHashMap();
map.put(itemmodelgenerator$spanfacing.getFacing(), new BlockPartFace((EnumFacing)null, p_178397_3_, p_178397_2_, new BlockFaceUV(new float[] {f6, f8, f7, f9}, 0)));
switch (itemmodelgenerator$spanfacing)
{
case UP:
list.add(new BlockPart(new Vector3f(f2, f3, 7.5F), new Vector3f(f4, f3, 8.5F), map, (BlockPartRotation)null, true));
break;
case DOWN:
list.add(new BlockPart(new Vector3f(f2, f5, 7.5F), new Vector3f(f4, f5, 8.5F), map, (BlockPartRotation)null, true));
break;
case LEFT:
list.add(new BlockPart(new Vector3f(f2, f3, 7.5F), new Vector3f(f2, f5, 8.5F), map, (BlockPartRotation)null, true));
break;
case RIGHT:
list.add(new BlockPart(new Vector3f(f4, f3, 7.5F), new Vector3f(f4, f5, 8.5F), map, (BlockPartRotation)null, true));
}
}
return list;
}
private List<ItemModelGenerator.Span> getSpans(TextureAtlasSprite p_178393_1_)
{
int i = p_178393_1_.getIconWidth();
int j = p_178393_1_.getIconHeight();
List<ItemModelGenerator.Span> list = Lists.<ItemModelGenerator.Span>newArrayList();
for (int k = 0; k < p_178393_1_.getFrameCount(); ++k)
{
int[] aint = p_178393_1_.getFrameTextureData(k)[0];
for (int l = 0; l < j; ++l)
{
for (int i1 = 0; i1 < i; ++i1)
{
boolean flag = !this.isTransparent(aint, i1, l, i, j);
this.checkTransition(ItemModelGenerator.SpanFacing.UP, list, aint, i1, l, i, j, flag);
this.checkTransition(ItemModelGenerator.SpanFacing.DOWN, list, aint, i1, l, i, j, flag);
this.checkTransition(ItemModelGenerator.SpanFacing.LEFT, list, aint, i1, l, i, j, flag);
this.checkTransition(ItemModelGenerator.SpanFacing.RIGHT, list, aint, i1, l, i, j, flag);
}
}
}
return list;
}
private void checkTransition(ItemModelGenerator.SpanFacing p_178396_1_, List<ItemModelGenerator.Span> p_178396_2_, int[] p_178396_3_, int p_178396_4_, int p_178396_5_, int p_178396_6_, int p_178396_7_, boolean p_178396_8_)
{
boolean flag = this.isTransparent(p_178396_3_, p_178396_4_ + p_178396_1_.getXOffset(), p_178396_5_ + p_178396_1_.getYOffset(), p_178396_6_, p_178396_7_) && p_178396_8_;
if (flag)
{
this.createOrExpandSpan(p_178396_2_, p_178396_1_, p_178396_4_, p_178396_5_);
}
}
private void createOrExpandSpan(List<ItemModelGenerator.Span> p_178395_1_, ItemModelGenerator.SpanFacing p_178395_2_, int p_178395_3_, int p_178395_4_)
{
ItemModelGenerator.Span itemmodelgenerator$span = null;
for (ItemModelGenerator.Span itemmodelgenerator$span1 : p_178395_1_)
{
if (itemmodelgenerator$span1.getFacing() == p_178395_2_)
{
int i = p_178395_2_.isHorizontal() ? p_178395_4_ : p_178395_3_;
if (itemmodelgenerator$span1.getAnchor() == i)
{
itemmodelgenerator$span = itemmodelgenerator$span1;
break;
}
}
}
int j = p_178395_2_.isHorizontal() ? p_178395_4_ : p_178395_3_;
int k = p_178395_2_.isHorizontal() ? p_178395_3_ : p_178395_4_;
if (itemmodelgenerator$span == null)
{
p_178395_1_.add(new ItemModelGenerator.Span(p_178395_2_, k, j));
}
else
{
itemmodelgenerator$span.expand(k);
}
}
private boolean isTransparent(int[] p_178391_1_, int p_178391_2_, int p_178391_3_, int p_178391_4_, int p_178391_5_)
{
if (p_178391_2_ >= 0 && p_178391_3_ >= 0 && p_178391_2_ < p_178391_4_ && p_178391_3_ < p_178391_5_)
{
return (p_178391_1_[p_178391_3_ * p_178391_4_ + p_178391_2_] >> 24 & 255) == 0;
}
else
{
return true;
}
}
@SideOnly(Side.CLIENT)
static class Span
{
private final ItemModelGenerator.SpanFacing spanFacing;
private int min;
private int max;
private final int anchor;
public Span(ItemModelGenerator.SpanFacing spanFacingIn, int p_i46216_2_, int p_i46216_3_)
{
this.spanFacing = spanFacingIn;
this.min = p_i46216_2_;
this.max = p_i46216_2_;
this.anchor = p_i46216_3_;
}
public void expand(int p_178382_1_)
{
if (p_178382_1_ < this.min)
{
this.min = p_178382_1_;
}
else if (p_178382_1_ > this.max)
{
this.max = p_178382_1_;
}
}
public ItemModelGenerator.SpanFacing getFacing()
{
return this.spanFacing;
}
public int getMin()
{
return this.min;
}
public int getMax()
{
return this.max;
}
public int getAnchor()
{
return this.anchor;
}
}
@SideOnly(Side.CLIENT)
static enum SpanFacing
{
UP(EnumFacing.UP, 0, -1),
DOWN(EnumFacing.DOWN, 0, 1),
LEFT(EnumFacing.EAST, -1, 0),
RIGHT(EnumFacing.WEST, 1, 0);
private final EnumFacing facing;
private final int xOffset;
private final int yOffset;
private SpanFacing(EnumFacing facing, int p_i46215_4_, int p_i46215_5_)
{
this.facing = facing;
this.xOffset = p_i46215_4_;
this.yOffset = p_i46215_5_;
}
/**
* Gets the direction of the block's facing.
*/
public EnumFacing getFacing()
{
return this.facing;
}
public int getXOffset()
{
return this.xOffset;
}
public int getYOffset()
{
return this.yOffset;
}
private boolean isHorizontal()
{
return this == DOWN || this == UP;
}
}
}

View File

@@ -0,0 +1,84 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.collect.Maps;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ItemOverride
{
private final ResourceLocation location;
private final Map<ResourceLocation, Float> mapResourceValues;
public ItemOverride(ResourceLocation locationIn, Map<ResourceLocation, Float> propertyValues)
{
this.location = locationIn;
this.mapResourceValues = propertyValues;
}
/**
* Get the location of the target model
*/
public ResourceLocation getLocation()
{
return this.location;
}
boolean matchesItemStack(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase livingEntity)
{
Item item = stack.getItem();
for (Entry<ResourceLocation, Float> entry : this.mapResourceValues.entrySet())
{
IItemPropertyGetter iitempropertygetter = item.getPropertyGetter(entry.getKey());
if (iitempropertygetter == null || iitempropertygetter.apply(stack, worldIn, livingEntity) < ((Float)entry.getValue()).floatValue())
{
return false;
}
}
return true;
}
@SideOnly(Side.CLIENT)
static class Deserializer implements JsonDeserializer<ItemOverride>
{
public ItemOverride deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
ResourceLocation resourcelocation = new ResourceLocation(JsonUtils.getString(jsonobject, "model"));
Map<ResourceLocation, Float> map = this.makeMapResourceValues(jsonobject);
return new ItemOverride(resourcelocation, map);
}
protected Map<ResourceLocation, Float> makeMapResourceValues(JsonObject p_188025_1_)
{
Map<ResourceLocation, Float> map = Maps.<ResourceLocation, Float>newLinkedHashMap();
JsonObject jsonobject = JsonUtils.getJsonObject(p_188025_1_, "predicate");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
map.put(new ResourceLocation(entry.getKey()), Float.valueOf(JsonUtils.getFloat(entry.getValue(), entry.getKey())));
}
return map;
}
}
}

View File

@@ -0,0 +1,66 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ItemOverrideList
{
public static final ItemOverrideList NONE = new ItemOverrideList();
private final List<ItemOverride> overrides = Lists.<ItemOverride>newArrayList();
private ItemOverrideList()
{
}
public ItemOverrideList(List<ItemOverride> overridesIn)
{
for (int i = overridesIn.size() - 1; i >= 0; --i)
{
this.overrides.add(overridesIn.get(i));
}
}
@Nullable
@Deprecated
public ResourceLocation applyOverride(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
{
if (!this.overrides.isEmpty())
{
for (ItemOverride itemoverride : this.overrides)
{
if (itemoverride.matchesItemStack(stack, worldIn, entityIn))
{
return itemoverride.getLocation();
}
}
}
return null;
}
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
if (!stack.isEmpty() && stack.getItem().hasCustomProperties())
{
ResourceLocation location = applyOverride(stack, world, entity);
if (location != null)
{
return net.minecraft.client.Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getModel(net.minecraftforge.client.model.ModelLoader.getInventoryVariant(location.toString()));
}
}
return originalModel;
}
public com.google.common.collect.ImmutableList<ItemOverride> getOverrides()
{
return com.google.common.collect.ImmutableList.copyOf(overrides);
}
}

View File

@@ -0,0 +1,112 @@
package net.minecraft.client.renderer.block.model;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
/*
* @deprecated use {@link net.minecraftforge.client.model.IModelState} and {@link net.minecraftforge.client.model.TRSRTransformation}
*/
@SideOnly(Side.CLIENT)
@Deprecated
public class ItemTransformVec3f implements net.minecraftforge.common.model.IModelState
{
public java.util.Optional<net.minecraftforge.common.model.TRSRTransformation> apply(java.util.Optional<? extends net.minecraftforge.common.model.IModelPart> part) { return net.minecraftforge.client.ForgeHooksClient.applyTransform(this, part); }
public static final ItemTransformVec3f DEFAULT = new ItemTransformVec3f(new Vector3f(), new Vector3f(), new Vector3f(1.0F, 1.0F, 1.0F));
public final Vector3f rotation;
public final Vector3f translation;
public final Vector3f scale;
public ItemTransformVec3f(Vector3f rotation, Vector3f translation, Vector3f scale)
{
this.rotation = new Vector3f(rotation);
this.translation = new Vector3f(translation);
this.scale = new Vector3f(scale);
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (this.getClass() != p_equals_1_.getClass())
{
return false;
}
else
{
ItemTransformVec3f itemtransformvec3f = (ItemTransformVec3f)p_equals_1_;
return this.rotation.equals(itemtransformvec3f.rotation) && this.scale.equals(itemtransformvec3f.scale) && this.translation.equals(itemtransformvec3f.translation);
}
}
public int hashCode()
{
int i = this.rotation.hashCode();
i = 31 * i + this.translation.hashCode();
i = 31 * i + this.scale.hashCode();
return i;
}
@SideOnly(Side.CLIENT)
static class Deserializer implements JsonDeserializer<ItemTransformVec3f>
{
private static final Vector3f ROTATION_DEFAULT = new Vector3f(0.0F, 0.0F, 0.0F);
private static final Vector3f TRANSLATION_DEFAULT = new Vector3f(0.0F, 0.0F, 0.0F);
private static final Vector3f SCALE_DEFAULT = new Vector3f(1.0F, 1.0F, 1.0F);
public ItemTransformVec3f deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
Vector3f vector3f = this.parseVector3f(jsonobject, "rotation", ROTATION_DEFAULT);
Vector3f vector3f1 = this.parseVector3f(jsonobject, "translation", TRANSLATION_DEFAULT);
vector3f1.scale(0.0625F);
vector3f1.x = MathHelper.clamp(vector3f1.x, -5.0F, 5.0F);
vector3f1.y = MathHelper.clamp(vector3f1.y, -5.0F, 5.0F);
vector3f1.z = MathHelper.clamp(vector3f1.z, -5.0F, 5.0F);
Vector3f vector3f2 = this.parseVector3f(jsonobject, "scale", SCALE_DEFAULT);
vector3f2.x = MathHelper.clamp(vector3f2.x, -4.0F, 4.0F);
vector3f2.y = MathHelper.clamp(vector3f2.y, -4.0F, 4.0F);
vector3f2.z = MathHelper.clamp(vector3f2.z, -4.0F, 4.0F);
return new ItemTransformVec3f(vector3f, vector3f1, vector3f2);
}
private Vector3f parseVector3f(JsonObject jsonObject, String key, Vector3f defaultValue)
{
if (!jsonObject.has(key))
{
return defaultValue;
}
else
{
JsonArray jsonarray = JsonUtils.getJsonArray(jsonObject, key);
if (jsonarray.size() != 3)
{
throw new JsonParseException("Expected 3 " + key + " values, found: " + jsonarray.size());
}
else
{
float[] afloat = new float[3];
for (int i = 0; i < afloat.length; ++i)
{
afloat[i] = JsonUtils.getFloat(jsonarray.get(i), key + "[" + i + "]");
}
return new Vector3f(afloat[0], afloat[1], afloat[2]);
}
}
}
}
}

View File

@@ -0,0 +1,964 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.block.model.multipart.Multipart;
import net.minecraft.client.renderer.block.model.multipart.Selector;
import net.minecraft.client.renderer.block.statemap.BlockStateMapper;
import net.minecraft.client.renderer.texture.ITextureMapPopulator;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import net.minecraft.util.registry.RegistrySimple;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class ModelBakery
{
protected static final Set<ResourceLocation> LOCATIONS_BUILTIN_TEXTURES = Sets.newHashSet(new ResourceLocation("blocks/water_flow"), new ResourceLocation("blocks/water_still"), new ResourceLocation("blocks/lava_flow"), new ResourceLocation("blocks/lava_still"), new ResourceLocation("blocks/water_overlay"), new ResourceLocation("blocks/destroy_stage_0"), new ResourceLocation("blocks/destroy_stage_1"), new ResourceLocation("blocks/destroy_stage_2"), new ResourceLocation("blocks/destroy_stage_3"), new ResourceLocation("blocks/destroy_stage_4"), new ResourceLocation("blocks/destroy_stage_5"), new ResourceLocation("blocks/destroy_stage_6"), new ResourceLocation("blocks/destroy_stage_7"), new ResourceLocation("blocks/destroy_stage_8"), new ResourceLocation("blocks/destroy_stage_9"), new ResourceLocation("items/empty_armor_slot_helmet"), new ResourceLocation("items/empty_armor_slot_chestplate"), new ResourceLocation("items/empty_armor_slot_leggings"), new ResourceLocation("items/empty_armor_slot_boots"), new ResourceLocation("items/empty_armor_slot_shield"), new ResourceLocation("blocks/shulker_top_white"), new ResourceLocation("blocks/shulker_top_orange"), new ResourceLocation("blocks/shulker_top_magenta"), new ResourceLocation("blocks/shulker_top_light_blue"), new ResourceLocation("blocks/shulker_top_yellow"), new ResourceLocation("blocks/shulker_top_lime"), new ResourceLocation("blocks/shulker_top_pink"), new ResourceLocation("blocks/shulker_top_gray"), new ResourceLocation("blocks/shulker_top_silver"), new ResourceLocation("blocks/shulker_top_cyan"), new ResourceLocation("blocks/shulker_top_purple"), new ResourceLocation("blocks/shulker_top_blue"), new ResourceLocation("blocks/shulker_top_brown"), new ResourceLocation("blocks/shulker_top_green"), new ResourceLocation("blocks/shulker_top_red"), new ResourceLocation("blocks/shulker_top_black"));
private static final Logger LOGGER = LogManager.getLogger();
public static final ModelResourceLocation MODEL_MISSING = new ModelResourceLocation("builtin/missing", "missing");
private static final String MISSING_MODEL_MESH = "{ 'textures': { 'particle': 'missingno', 'missingno': 'missingno' }, 'elements': [ { 'from': [ 0, 0, 0 ], 'to': [ 16, 16, 16 ], 'faces': { 'down': { 'uv': [ 0, 0, 16, 16 ], 'cullface': 'down', 'texture': '#missingno' }, 'up': { 'uv': [ 0, 0, 16, 16 ], 'cullface': 'up', 'texture': '#missingno' }, 'north': { 'uv': [ 0, 0, 16, 16 ], 'cullface': 'north', 'texture': '#missingno' }, 'south': { 'uv': [ 0, 0, 16, 16 ], 'cullface': 'south', 'texture': '#missingno' }, 'west': { 'uv': [ 0, 0, 16, 16 ], 'cullface': 'west', 'texture': '#missingno' }, 'east': { 'uv': [ 0, 0, 16, 16 ], 'cullface': 'east', 'texture': '#missingno' } } } ]}".replaceAll("'", "\"");
private static final Map<String, String> BUILT_IN_MODELS = Maps.<String, String>newHashMap();
private static final Joiner JOINER = Joiner.on(" -> ");
protected final IResourceManager resourceManager;
protected final Map<ResourceLocation, TextureAtlasSprite> sprites = Maps.<ResourceLocation, TextureAtlasSprite>newHashMap();
private final Map<ResourceLocation, ModelBlock> models = Maps.<ResourceLocation, ModelBlock>newLinkedHashMap();
private final Map<ModelResourceLocation, VariantList> variants = Maps.<ModelResourceLocation, VariantList>newLinkedHashMap();
private final Map<ModelBlockDefinition, Collection<ModelResourceLocation>> multipartVariantMap = Maps.<ModelBlockDefinition, Collection<ModelResourceLocation>>newLinkedHashMap();
protected final TextureMap textureMap;
protected final BlockModelShapes blockModelShapes;
private final FaceBakery faceBakery = new FaceBakery();
private final ItemModelGenerator itemModelGenerator = new ItemModelGenerator();
protected final RegistrySimple<ModelResourceLocation, IBakedModel> bakedRegistry = new RegistrySimple<ModelResourceLocation, IBakedModel>();
private static final String EMPTY_MODEL_RAW = "{ 'elements': [ { 'from': [0, 0, 0], 'to': [16, 16, 16], 'faces': { 'down': {'uv': [0, 0, 16, 16], 'texture': '' } } } ]}".replaceAll("'", "\"");
protected static final ModelBlock MODEL_GENERATED = ModelBlock.deserialize(EMPTY_MODEL_RAW);
protected static final ModelBlock MODEL_ENTITY = ModelBlock.deserialize(EMPTY_MODEL_RAW);
private final Map<String, ResourceLocation> itemLocations = Maps.<String, ResourceLocation>newLinkedHashMap();
private final Map<ResourceLocation, ModelBlockDefinition> blockDefinitions = Maps.<ResourceLocation, ModelBlockDefinition>newHashMap();
private final Map<Item, List<String>> variantNames = Maps.<Item, List<String>>newIdentityHashMap();
public ModelBakery(IResourceManager resourceManagerIn, TextureMap textureMapIn, BlockModelShapes blockModelShapesIn)
{
this.resourceManager = resourceManagerIn;
this.textureMap = textureMapIn;
this.blockModelShapes = blockModelShapesIn;
}
public IRegistry<ModelResourceLocation, IBakedModel> setupModelRegistry()
{
this.loadBlocks();
this.loadVariantItemModels();
this.loadModelsCheck();
this.loadSprites();
this.makeItemModels();
this.bakeBlockModels();
this.bakeItemModels();
return this.bakedRegistry;
}
protected void loadBlocks()
{
BlockStateMapper blockstatemapper = this.blockModelShapes.getBlockStateMapper();
for (Block block : Block.REGISTRY)
{
for (final ResourceLocation resourcelocation : blockstatemapper.getBlockstateLocations(block))
{
try
{
loadBlock(blockstatemapper, block, resourcelocation);
}
catch (Exception exception)
{
LOGGER.warn((String)("Unable to load definition " + resourcelocation), (Throwable)exception);
}
}
}
}
protected void loadBlock(BlockStateMapper blockstatemapper, Block block, final ResourceLocation resourcelocation)
{
{
{
{
ModelBlockDefinition modelblockdefinition = this.getModelBlockDefinition(resourcelocation);
Map<IBlockState, ModelResourceLocation> map = blockstatemapper.getVariants(block);
if (modelblockdefinition.hasMultipartData())
{
Collection<ModelResourceLocation> collection = Sets.newHashSet(map.values());
modelblockdefinition.getMultipartData().setStateContainer(block.getBlockState());
Collection<ModelResourceLocation> collection1 = (Collection)this.multipartVariantMap.get(modelblockdefinition);
if (collection1 == null)
{
collection1 = Lists.<ModelResourceLocation>newArrayList();
}
collection1.addAll(Lists.newArrayList(Iterables.filter(collection, new Predicate<ModelResourceLocation>()
{
public boolean apply(@Nullable ModelResourceLocation p_apply_1_)
{
return resourcelocation.equals(p_apply_1_);
}
})));
registerMultipartVariant(modelblockdefinition, collection1);
}
for (Entry<IBlockState, ModelResourceLocation> entry : map.entrySet())
{
ModelResourceLocation modelresourcelocation = entry.getValue();
if (resourcelocation.equals(modelresourcelocation))
{
try
{
registerVariant(modelblockdefinition, modelresourcelocation);
}
catch (RuntimeException var12)
{
if (!modelblockdefinition.hasMultipartData())
{
LOGGER.warn("Unable to load variant: " + modelresourcelocation.getVariant() + " from " + modelresourcelocation, var12);
}
}
}
}
}
}
}
}
protected void loadVariantItemModels()
{
this.variants.put(MODEL_MISSING, new VariantList(Lists.newArrayList(new Variant(new ResourceLocation(MODEL_MISSING.getResourcePath()), ModelRotation.X0_Y0, false, 1))));
this.loadStaticModels();
this.loadVariantModels();
this.loadMultipartVariantModels();
this.loadItemModels();
}
private void loadStaticModels()
{
ResourceLocation resourcelocation = new ResourceLocation("item_frame");
ModelBlockDefinition modelblockdefinition = this.getModelBlockDefinition(resourcelocation);
this.registerVariant(modelblockdefinition, new ModelResourceLocation(resourcelocation, "normal"));
this.registerVariant(modelblockdefinition, new ModelResourceLocation(resourcelocation, "map"));
}
protected void registerVariant(ModelBlockDefinition blockstateDefinition, ModelResourceLocation location)
{
try
{
this.variants.put(location, blockstateDefinition.getVariant(location.getVariant()));
}
catch (RuntimeException var4)
{
if (!blockstateDefinition.hasMultipartData())
{
LOGGER.warn("Unable to load variant: {} from {}", location.getVariant(), location);
}
}
}
protected ModelBlockDefinition getModelBlockDefinition(ResourceLocation location)
{
ResourceLocation resourcelocation = this.getBlockstateLocation(location);
ModelBlockDefinition modelblockdefinition = this.blockDefinitions.get(resourcelocation);
if (modelblockdefinition == null)
{
modelblockdefinition = this.loadMultipartMBD(location, resourcelocation);
this.blockDefinitions.put(resourcelocation, modelblockdefinition);
}
return modelblockdefinition;
}
private ModelBlockDefinition loadMultipartMBD(ResourceLocation location, ResourceLocation fileIn)
{
List<ModelBlockDefinition> list = Lists.<ModelBlockDefinition>newArrayList();
try
{
for (IResource iresource : this.resourceManager.getAllResources(fileIn))
{
list.add(this.loadModelBlockDefinition(location, iresource));
}
}
catch (IOException ioexception)
{
throw new RuntimeException("Encountered an exception when loading model definition of model " + fileIn, ioexception);
}
return new ModelBlockDefinition(list);
}
private ModelBlockDefinition loadModelBlockDefinition(ResourceLocation location, IResource resource)
{
InputStream inputstream = null;
ModelBlockDefinition lvt_4_1_;
try
{
inputstream = resource.getInputStream();
lvt_4_1_ = ModelBlockDefinition.parseFromReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8), location);
}
catch (Exception exception)
{
throw new RuntimeException("Encountered an exception when loading model definition of '" + location + "' from: '" + resource.getResourceLocation() + "' in resourcepack: '" + resource.getResourcePackName() + "'", exception);
}
finally
{
IOUtils.closeQuietly(inputstream);
}
return lvt_4_1_;
}
private ResourceLocation getBlockstateLocation(ResourceLocation location)
{
return new ResourceLocation(location.getResourceDomain(), "blockstates/" + location.getResourcePath() + ".json");
}
protected void loadVariantModels()
{
for (Entry<ModelResourceLocation, VariantList> entry : this.variants.entrySet())
{
this.loadVariantList(entry.getKey(), entry.getValue());
}
}
protected void loadMultipartVariantModels()
{
for (Entry<ModelBlockDefinition, Collection<ModelResourceLocation>> entry : this.multipartVariantMap.entrySet())
{
ModelResourceLocation modelresourcelocation = (ModelResourceLocation)(entry.getValue()).iterator().next();
for (VariantList variantlist : (entry.getKey()).getMultipartVariants())
{
this.loadVariantList(modelresourcelocation, variantlist);
}
}
}
protected void loadVariantList(ModelResourceLocation p_188638_1_, VariantList p_188638_2_)
{
for (Variant variant : p_188638_2_.getVariantList())
{
ResourceLocation resourcelocation = variant.getModelLocation();
if (this.models.get(resourcelocation) == null)
{
try
{
this.models.put(resourcelocation, this.loadModel(resourcelocation));
}
catch (Exception exception)
{
LOGGER.warn("Unable to load block model: '{}' for variant: '{}': {} ", resourcelocation, p_188638_1_, exception);
}
}
}
}
protected ModelBlock loadModel(ResourceLocation location) throws IOException
{
Reader reader = null;
IResource iresource = null;
ModelBlock lvt_5_2_;
try
{
String s = location.getResourcePath();
if (!"builtin/generated".equals(s))
{
if ("builtin/entity".equals(s))
{
lvt_5_2_ = MODEL_ENTITY;
return lvt_5_2_;
}
if (s.startsWith("builtin/"))
{
String s2 = s.substring("builtin/".length());
String s1 = BUILT_IN_MODELS.get(s2);
if (s1 == null)
{
throw new FileNotFoundException(location.toString());
}
reader = new StringReader(s1);
}
else
{
iresource = this.resourceManager.getResource(this.getModelLocation(location));
reader = new InputStreamReader(iresource.getInputStream(), StandardCharsets.UTF_8);
}
lvt_5_2_ = ModelBlock.deserialize(reader);
lvt_5_2_.name = location.toString();
ModelBlock modelblock1 = lvt_5_2_;
return modelblock1;
}
lvt_5_2_ = MODEL_GENERATED;
}
finally
{
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly((Closeable)iresource);
}
return lvt_5_2_;
}
protected ResourceLocation getModelLocation(ResourceLocation location)
{
return new ResourceLocation(location.getResourceDomain(), "models/" + location.getResourcePath() + ".json");
}
protected void loadItemModels()
{
this.registerVariantNames();
for (Item item : Item.REGISTRY)
{
for (String s : this.getVariantNames(item))
{
ResourceLocation resourcelocation = this.getItemLocation(s);
ResourceLocation resourcelocation1 = Item.REGISTRY.getNameForObject(item);
this.loadItemModel(s, resourcelocation, resourcelocation1);
if (item.hasCustomProperties())
{
ModelBlock modelblock = this.models.get(resourcelocation);
if (modelblock != null)
{
for (ResourceLocation resourcelocation2 : modelblock.getOverrideLocations())
{
this.loadItemModel(resourcelocation2.toString(), resourcelocation2, resourcelocation1);
}
}
}
}
}
}
private void loadItemModel(String variantName, ResourceLocation location, ResourceLocation itemName)
{
this.itemLocations.put(variantName, location);
if (this.models.get(location) == null)
{
try
{
ModelBlock modelblock = this.loadModel(location);
this.models.put(location, modelblock);
}
catch (Exception exception)
{
LOGGER.warn("Unable to load item model: '{}' for item: '{}'", location, itemName, exception);
}
}
}
protected void registerVariantNames()
{
this.variantNames.clear(); // FML clear this to prevent double ups.
this.variantNames.put(Item.getItemFromBlock(Blocks.STONE), Lists.newArrayList("stone", "granite", "granite_smooth", "diorite", "diorite_smooth", "andesite", "andesite_smooth"));
this.variantNames.put(Item.getItemFromBlock(Blocks.DIRT), Lists.newArrayList("dirt", "coarse_dirt", "podzol"));
this.variantNames.put(Item.getItemFromBlock(Blocks.PLANKS), Lists.newArrayList("oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks"));
this.variantNames.put(Item.getItemFromBlock(Blocks.SAPLING), Lists.newArrayList("oak_sapling", "spruce_sapling", "birch_sapling", "jungle_sapling", "acacia_sapling", "dark_oak_sapling"));
this.variantNames.put(Item.getItemFromBlock(Blocks.SAND), Lists.newArrayList("sand", "red_sand"));
this.variantNames.put(Item.getItemFromBlock(Blocks.LOG), Lists.newArrayList("oak_log", "spruce_log", "birch_log", "jungle_log"));
this.variantNames.put(Item.getItemFromBlock(Blocks.LEAVES), Lists.newArrayList("oak_leaves", "spruce_leaves", "birch_leaves", "jungle_leaves"));
this.variantNames.put(Item.getItemFromBlock(Blocks.SPONGE), Lists.newArrayList("sponge", "sponge_wet"));
this.variantNames.put(Item.getItemFromBlock(Blocks.SANDSTONE), Lists.newArrayList("sandstone", "chiseled_sandstone", "smooth_sandstone"));
this.variantNames.put(Item.getItemFromBlock(Blocks.RED_SANDSTONE), Lists.newArrayList("red_sandstone", "chiseled_red_sandstone", "smooth_red_sandstone"));
this.variantNames.put(Item.getItemFromBlock(Blocks.TALLGRASS), Lists.newArrayList("dead_bush", "tall_grass", "fern"));
this.variantNames.put(Item.getItemFromBlock(Blocks.DEADBUSH), Lists.newArrayList("dead_bush"));
this.variantNames.put(Item.getItemFromBlock(Blocks.WOOL), Lists.newArrayList("black_wool", "red_wool", "green_wool", "brown_wool", "blue_wool", "purple_wool", "cyan_wool", "silver_wool", "gray_wool", "pink_wool", "lime_wool", "yellow_wool", "light_blue_wool", "magenta_wool", "orange_wool", "white_wool"));
this.variantNames.put(Item.getItemFromBlock(Blocks.YELLOW_FLOWER), Lists.newArrayList("dandelion"));
this.variantNames.put(Item.getItemFromBlock(Blocks.RED_FLOWER), Lists.newArrayList("poppy", "blue_orchid", "allium", "houstonia", "red_tulip", "orange_tulip", "white_tulip", "pink_tulip", "oxeye_daisy"));
this.variantNames.put(Item.getItemFromBlock(Blocks.STONE_SLAB), Lists.newArrayList("stone_slab", "sandstone_slab", "cobblestone_slab", "brick_slab", "stone_brick_slab", "nether_brick_slab", "quartz_slab"));
this.variantNames.put(Item.getItemFromBlock(Blocks.STONE_SLAB2), Lists.newArrayList("red_sandstone_slab"));
this.variantNames.put(Item.getItemFromBlock(Blocks.STAINED_GLASS), Lists.newArrayList("black_stained_glass", "red_stained_glass", "green_stained_glass", "brown_stained_glass", "blue_stained_glass", "purple_stained_glass", "cyan_stained_glass", "silver_stained_glass", "gray_stained_glass", "pink_stained_glass", "lime_stained_glass", "yellow_stained_glass", "light_blue_stained_glass", "magenta_stained_glass", "orange_stained_glass", "white_stained_glass"));
this.variantNames.put(Item.getItemFromBlock(Blocks.MONSTER_EGG), Lists.newArrayList("stone_monster_egg", "cobblestone_monster_egg", "stone_brick_monster_egg", "mossy_brick_monster_egg", "cracked_brick_monster_egg", "chiseled_brick_monster_egg"));
this.variantNames.put(Item.getItemFromBlock(Blocks.STONEBRICK), Lists.newArrayList("stonebrick", "mossy_stonebrick", "cracked_stonebrick", "chiseled_stonebrick"));
this.variantNames.put(Item.getItemFromBlock(Blocks.WOODEN_SLAB), Lists.newArrayList("oak_slab", "spruce_slab", "birch_slab", "jungle_slab", "acacia_slab", "dark_oak_slab"));
this.variantNames.put(Item.getItemFromBlock(Blocks.COBBLESTONE_WALL), Lists.newArrayList("cobblestone_wall", "mossy_cobblestone_wall"));
this.variantNames.put(Item.getItemFromBlock(Blocks.ANVIL), Lists.newArrayList("anvil_intact", "anvil_slightly_damaged", "anvil_very_damaged"));
this.variantNames.put(Item.getItemFromBlock(Blocks.QUARTZ_BLOCK), Lists.newArrayList("quartz_block", "chiseled_quartz_block", "quartz_column"));
this.variantNames.put(Item.getItemFromBlock(Blocks.STAINED_HARDENED_CLAY), Lists.newArrayList("black_stained_hardened_clay", "red_stained_hardened_clay", "green_stained_hardened_clay", "brown_stained_hardened_clay", "blue_stained_hardened_clay", "purple_stained_hardened_clay", "cyan_stained_hardened_clay", "silver_stained_hardened_clay", "gray_stained_hardened_clay", "pink_stained_hardened_clay", "lime_stained_hardened_clay", "yellow_stained_hardened_clay", "light_blue_stained_hardened_clay", "magenta_stained_hardened_clay", "orange_stained_hardened_clay", "white_stained_hardened_clay"));
this.variantNames.put(Item.getItemFromBlock(Blocks.STAINED_GLASS_PANE), Lists.newArrayList("black_stained_glass_pane", "red_stained_glass_pane", "green_stained_glass_pane", "brown_stained_glass_pane", "blue_stained_glass_pane", "purple_stained_glass_pane", "cyan_stained_glass_pane", "silver_stained_glass_pane", "gray_stained_glass_pane", "pink_stained_glass_pane", "lime_stained_glass_pane", "yellow_stained_glass_pane", "light_blue_stained_glass_pane", "magenta_stained_glass_pane", "orange_stained_glass_pane", "white_stained_glass_pane"));
this.variantNames.put(Item.getItemFromBlock(Blocks.LEAVES2), Lists.newArrayList("acacia_leaves", "dark_oak_leaves"));
this.variantNames.put(Item.getItemFromBlock(Blocks.LOG2), Lists.newArrayList("acacia_log", "dark_oak_log"));
this.variantNames.put(Item.getItemFromBlock(Blocks.PRISMARINE), Lists.newArrayList("prismarine", "prismarine_bricks", "dark_prismarine"));
this.variantNames.put(Item.getItemFromBlock(Blocks.CARPET), Lists.newArrayList("black_carpet", "red_carpet", "green_carpet", "brown_carpet", "blue_carpet", "purple_carpet", "cyan_carpet", "silver_carpet", "gray_carpet", "pink_carpet", "lime_carpet", "yellow_carpet", "light_blue_carpet", "magenta_carpet", "orange_carpet", "white_carpet"));
this.variantNames.put(Item.getItemFromBlock(Blocks.DOUBLE_PLANT), Lists.newArrayList("sunflower", "syringa", "double_grass", "double_fern", "double_rose", "paeonia"));
this.variantNames.put(Items.COAL, Lists.newArrayList("coal", "charcoal"));
this.variantNames.put(Items.FISH, Lists.newArrayList("cod", "salmon", "clownfish", "pufferfish"));
this.variantNames.put(Items.COOKED_FISH, Lists.newArrayList("cooked_cod", "cooked_salmon"));
this.variantNames.put(Items.DYE, Lists.newArrayList("dye_black", "dye_red", "dye_green", "dye_brown", "dye_blue", "dye_purple", "dye_cyan", "dye_silver", "dye_gray", "dye_pink", "dye_lime", "dye_yellow", "dye_light_blue", "dye_magenta", "dye_orange", "dye_white"));
this.variantNames.put(Items.POTIONITEM, Lists.newArrayList("bottle_drinkable"));
this.variantNames.put(Items.SKULL, Lists.newArrayList("skull_skeleton", "skull_wither", "skull_zombie", "skull_char", "skull_creeper", "skull_dragon"));
this.variantNames.put(Items.SPLASH_POTION, Lists.newArrayList("bottle_splash"));
this.variantNames.put(Items.LINGERING_POTION, Lists.newArrayList("bottle_lingering"));
this.variantNames.put(Item.getItemFromBlock(Blocks.CONCRETE), Lists.newArrayList("black_concrete", "red_concrete", "green_concrete", "brown_concrete", "blue_concrete", "purple_concrete", "cyan_concrete", "silver_concrete", "gray_concrete", "pink_concrete", "lime_concrete", "yellow_concrete", "light_blue_concrete", "magenta_concrete", "orange_concrete", "white_concrete"));
this.variantNames.put(Item.getItemFromBlock(Blocks.CONCRETE_POWDER), Lists.newArrayList("black_concrete_powder", "red_concrete_powder", "green_concrete_powder", "brown_concrete_powder", "blue_concrete_powder", "purple_concrete_powder", "cyan_concrete_powder", "silver_concrete_powder", "gray_concrete_powder", "pink_concrete_powder", "lime_concrete_powder", "yellow_concrete_powder", "light_blue_concrete_powder", "magenta_concrete_powder", "orange_concrete_powder", "white_concrete_powder"));
this.variantNames.put(Item.getItemFromBlock(Blocks.AIR), Collections.emptyList());
this.variantNames.put(Item.getItemFromBlock(Blocks.OAK_FENCE_GATE), Lists.newArrayList("oak_fence_gate"));
this.variantNames.put(Item.getItemFromBlock(Blocks.OAK_FENCE), Lists.newArrayList("oak_fence"));
this.variantNames.put(Items.OAK_DOOR, Lists.newArrayList("oak_door"));
this.variantNames.put(Items.BOAT, Lists.newArrayList("oak_boat"));
this.variantNames.put(Items.TOTEM_OF_UNDYING, Lists.newArrayList("totem"));
for (Entry<net.minecraftforge.registries.IRegistryDelegate<Item>, Set<String>> e : customVariantNames.entrySet())
{
this.variantNames.put(e.getKey().get(), Lists.newArrayList(e.getValue().iterator()));
}
}
protected List<String> getVariantNames(Item stack)
{
List<String> list = (List)this.variantNames.get(stack);
if (list == null)
{
list = Collections.<String>singletonList(((ResourceLocation)Item.REGISTRY.getNameForObject(stack)).toString());
}
return list;
}
protected ResourceLocation getItemLocation(String location)
{
ResourceLocation resourcelocation = new ResourceLocation(location.replaceAll("#.*", ""));
return new ResourceLocation(resourcelocation.getResourceDomain(), "item/" + resourcelocation.getResourcePath());
}
private void bakeBlockModels()
{
for (ModelResourceLocation modelresourcelocation : this.variants.keySet())
{
IBakedModel ibakedmodel = this.createRandomModelForVariantList(this.variants.get(modelresourcelocation), modelresourcelocation.toString());
if (ibakedmodel != null)
{
this.bakedRegistry.putObject(modelresourcelocation, ibakedmodel);
}
}
for (Entry<ModelBlockDefinition, Collection<ModelResourceLocation>> entry : this.multipartVariantMap.entrySet())
{
ModelBlockDefinition modelblockdefinition = entry.getKey();
Multipart multipart = modelblockdefinition.getMultipartData();
String s = ((ResourceLocation)Block.REGISTRY.getNameForObject(multipart.getStateContainer().getBlock())).toString();
MultipartBakedModel.Builder multipartbakedmodel$builder = new MultipartBakedModel.Builder();
for (Selector selector : multipart.getSelectors())
{
IBakedModel ibakedmodel1 = this.createRandomModelForVariantList(selector.getVariantList(), "selector of " + s);
if (ibakedmodel1 != null)
{
multipartbakedmodel$builder.putModel(selector.getPredicate(multipart.getStateContainer()), ibakedmodel1);
}
}
IBakedModel ibakedmodel2 = multipartbakedmodel$builder.makeMultipartModel();
for (ModelResourceLocation modelresourcelocation1 : entry.getValue())
{
if (!modelblockdefinition.hasVariant(modelresourcelocation1.getVariant()))
{
this.bakedRegistry.putObject(modelresourcelocation1, ibakedmodel2);
}
}
}
}
@Nullable
private IBakedModel createRandomModelForVariantList(VariantList variantsIn, String modelLocation)
{
if (variantsIn.getVariantList().isEmpty())
{
return null;
}
else
{
WeightedBakedModel.Builder weightedbakedmodel$builder = new WeightedBakedModel.Builder();
int i = 0;
for (Variant variant : variantsIn.getVariantList())
{
ModelBlock modelblock = this.models.get(variant.getModelLocation());
if (modelblock != null && modelblock.isResolved())
{
if (modelblock.getElements().isEmpty())
{
LOGGER.warn("Missing elements for: {}", (Object)modelLocation);
}
else
{
IBakedModel ibakedmodel = this.bakeModel(modelblock, variant.getRotation(), variant.isUvLock());
if (ibakedmodel != null)
{
++i;
weightedbakedmodel$builder.add(ibakedmodel, variant.getWeight());
}
}
}
else
{
LOGGER.warn("Missing model for: {}", (Object)modelLocation);
}
}
IBakedModel ibakedmodel1 = null;
if (i == 0)
{
LOGGER.warn("No weighted models for: {}", (Object)modelLocation);
}
else if (i == 1)
{
ibakedmodel1 = weightedbakedmodel$builder.first();
}
else
{
ibakedmodel1 = weightedbakedmodel$builder.build();
}
return ibakedmodel1;
}
}
private void bakeItemModels()
{
for (Entry<String, ResourceLocation> entry : this.itemLocations.entrySet())
{
ResourceLocation resourcelocation = entry.getValue();
ModelResourceLocation modelresourcelocation = net.minecraftforge.client.model.ModelLoader.getInventoryVariant(entry.getKey());
ModelBlock modelblock = this.models.get(resourcelocation);
if (modelblock != null && modelblock.isResolved())
{
if (modelblock.getElements().isEmpty())
{
LOGGER.warn("Missing elements for: {}", (Object)resourcelocation);
}
else if (this.isCustomRenderer(modelblock))
{
this.bakedRegistry.putObject(modelresourcelocation, new BuiltInModel(modelblock.getAllTransforms(), modelblock.createOverrides()));
}
else
{
IBakedModel ibakedmodel = this.bakeModel(modelblock, ModelRotation.X0_Y0, false);
if (ibakedmodel != null)
{
this.bakedRegistry.putObject(modelresourcelocation, ibakedmodel);
}
}
}
else
{
LOGGER.warn("Missing model for: {}", (Object)resourcelocation);
}
}
}
private Set<ResourceLocation> getVariantsTextureLocations()
{
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
List<ModelResourceLocation> list = Lists.newArrayList(this.variants.keySet());
Collections.sort(list, new Comparator<ModelResourceLocation>()
{
public int compare(ModelResourceLocation p_compare_1_, ModelResourceLocation p_compare_2_)
{
return p_compare_1_.toString().compareTo(p_compare_2_.toString());
}
});
for (ModelResourceLocation modelresourcelocation : list)
{
VariantList variantlist = this.variants.get(modelresourcelocation);
for (Variant variant : variantlist.getVariantList())
{
ModelBlock modelblock = this.models.get(variant.getModelLocation());
if (modelblock == null)
{
LOGGER.warn("Missing model for: {}", (Object)modelresourcelocation);
}
else
{
set.addAll(this.getTextureLocations(modelblock));
}
}
}
for (ModelBlockDefinition modelblockdefinition : this.multipartVariantMap.keySet())
{
for (VariantList variantlist1 : modelblockdefinition.getMultipartData().getVariants())
{
for (Variant variant1 : variantlist1.getVariantList())
{
ModelBlock modelblock1 = this.models.get(variant1.getModelLocation());
if (modelblock1 == null)
{
LOGGER.warn("Missing model for: {}", Block.REGISTRY.getNameForObject(modelblockdefinition.getMultipartData().getStateContainer().getBlock()));
}
else
{
set.addAll(this.getTextureLocations(modelblock1));
}
}
}
}
set.addAll(LOCATIONS_BUILTIN_TEXTURES);
return set;
}
@Nullable
private IBakedModel bakeModel(ModelBlock modelBlockIn, ModelRotation modelRotationIn, boolean uvLocked)
{
return bakeModel(modelBlockIn, (net.minecraftforge.common.model.ITransformation)modelRotationIn, uvLocked);
}
protected IBakedModel bakeModel(ModelBlock modelBlockIn, net.minecraftforge.common.model.ITransformation modelRotationIn, boolean uvLocked)
{
TextureAtlasSprite textureatlassprite = this.sprites.get(new ResourceLocation(modelBlockIn.resolveTextureName("particle")));
SimpleBakedModel.Builder simplebakedmodel$builder = (new SimpleBakedModel.Builder(modelBlockIn, modelBlockIn.createOverrides())).setTexture(textureatlassprite);
if (modelBlockIn.getElements().isEmpty())
{
return null;
}
else
{
for (BlockPart blockpart : modelBlockIn.getElements())
{
for (EnumFacing enumfacing : blockpart.mapFaces.keySet())
{
BlockPartFace blockpartface = blockpart.mapFaces.get(enumfacing);
TextureAtlasSprite textureatlassprite1 = this.sprites.get(new ResourceLocation(modelBlockIn.resolveTextureName(blockpartface.texture)));
if (blockpartface.cullFace == null || !net.minecraftforge.common.model.TRSRTransformation.isInteger(modelRotationIn.getMatrix()))
{
simplebakedmodel$builder.addGeneralQuad(this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, modelRotationIn, uvLocked));
}
else
{
simplebakedmodel$builder.addFaceQuad(modelRotationIn.rotate(blockpartface.cullFace), this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, modelRotationIn, uvLocked));
}
}
}
return simplebakedmodel$builder.makeBakedModel();
}
}
private BakedQuad makeBakedQuad(BlockPart p_177589_1_, BlockPartFace p_177589_2_, TextureAtlasSprite p_177589_3_, EnumFacing p_177589_4_, ModelRotation p_177589_5_, boolean p_177589_6_)
{
return makeBakedQuad(p_177589_1_, p_177589_2_, p_177589_3_, p_177589_4_, (net.minecraftforge.common.model.ITransformation)p_177589_5_, p_177589_6_);
}
protected BakedQuad makeBakedQuad(BlockPart p_177589_1_, BlockPartFace p_177589_2_, TextureAtlasSprite p_177589_3_, EnumFacing p_177589_4_, net.minecraftforge.common.model.ITransformation p_177589_5_, boolean p_177589_6_)
{
return this.faceBakery.makeBakedQuad(p_177589_1_.positionFrom, p_177589_1_.positionTo, p_177589_2_, p_177589_3_, p_177589_4_, p_177589_5_, p_177589_1_.partRotation, p_177589_6_, p_177589_1_.shade);
}
private void loadModelsCheck()
{
this.loadModels();
for (ModelBlock modelblock : this.models.values())
{
modelblock.getParentFromMap(this.models);
}
ModelBlock.checkModelHierarchy(this.models);
}
private void loadModels()
{
Deque<ResourceLocation> deque = Queues.<ResourceLocation>newArrayDeque();
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
for (ResourceLocation resourcelocation : this.models.keySet())
{
set.add(resourcelocation);
this.addModelParentLocation(deque, set, this.models.get(resourcelocation));
}
while (!deque.isEmpty())
{
ResourceLocation resourcelocation1 = deque.pop();
try
{
if (this.models.get(resourcelocation1) != null)
{
continue;
}
ModelBlock modelblock = this.loadModel(resourcelocation1);
this.models.put(resourcelocation1, modelblock);
this.addModelParentLocation(deque, set, modelblock);
}
catch (Exception exception)
{
LOGGER.warn("In parent chain: {}; unable to load model: '{}'", JOINER.join(this.getParentPath(resourcelocation1)), resourcelocation1, exception);
}
set.add(resourcelocation1);
}
}
private void addModelParentLocation(Deque<ResourceLocation> p_188633_1_, Set<ResourceLocation> p_188633_2_, ModelBlock p_188633_3_)
{
ResourceLocation resourcelocation = p_188633_3_.getParentLocation();
if (resourcelocation != null && !p_188633_2_.contains(resourcelocation))
{
p_188633_1_.add(resourcelocation);
}
}
private List<ResourceLocation> getParentPath(ResourceLocation p_177573_1_)
{
List<ResourceLocation> list = Lists.newArrayList(p_177573_1_);
ResourceLocation resourcelocation = p_177573_1_;
while ((resourcelocation = this.getParentLocation(resourcelocation)) != null)
{
list.add(0, resourcelocation);
}
return list;
}
@Nullable
private ResourceLocation getParentLocation(ResourceLocation p_177576_1_)
{
for (Entry<ResourceLocation, ModelBlock> entry : this.models.entrySet())
{
ModelBlock modelblock = entry.getValue();
if (modelblock != null && p_177576_1_.equals(modelblock.getParentLocation()))
{
return entry.getKey();
}
}
return null;
}
protected Set<ResourceLocation> getTextureLocations(ModelBlock p_177585_1_)
{
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
for (BlockPart blockpart : p_177585_1_.getElements())
{
for (BlockPartFace blockpartface : blockpart.mapFaces.values())
{
ResourceLocation resourcelocation = new ResourceLocation(p_177585_1_.resolveTextureName(blockpartface.texture));
set.add(resourcelocation);
}
}
set.add(new ResourceLocation(p_177585_1_.resolveTextureName("particle")));
return set;
}
private void loadSprites()
{
final Set<ResourceLocation> set = this.getVariantsTextureLocations();
set.addAll(this.getItemsTextureLocations());
set.remove(TextureMap.LOCATION_MISSING_TEXTURE);
ITextureMapPopulator itexturemappopulator = new ITextureMapPopulator()
{
public void registerSprites(TextureMap textureMapIn)
{
for (ResourceLocation resourcelocation : set)
{
TextureAtlasSprite textureatlassprite = textureMapIn.registerSprite(resourcelocation);
ModelBakery.this.sprites.put(resourcelocation, textureatlassprite);
}
}
};
this.textureMap.loadSprites(this.resourceManager, itexturemappopulator);
this.sprites.put(new ResourceLocation("missingno"), this.textureMap.getMissingSprite());
}
private Set<ResourceLocation> getItemsTextureLocations()
{
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
for (ResourceLocation resourcelocation : this.itemLocations.values())
{
ModelBlock modelblock = this.models.get(resourcelocation);
if (modelblock != null)
{
set.add(new ResourceLocation(modelblock.resolveTextureName("particle")));
if (this.hasItemModel(modelblock))
{
for (String s : ItemModelGenerator.LAYERS)
{
set.add(new ResourceLocation(modelblock.resolveTextureName(s)));
}
}
else if (!this.isCustomRenderer(modelblock))
{
for (BlockPart blockpart : modelblock.getElements())
{
for (BlockPartFace blockpartface : blockpart.mapFaces.values())
{
ResourceLocation resourcelocation1 = new ResourceLocation(modelblock.resolveTextureName(blockpartface.texture));
set.add(resourcelocation1);
}
}
}
}
}
return set;
}
protected boolean hasItemModel(@Nullable ModelBlock p_177581_1_)
{
if (p_177581_1_ == null)
{
return false;
}
else
{
return p_177581_1_.getRootModel() == MODEL_GENERATED;
}
}
protected boolean isCustomRenderer(@Nullable ModelBlock p_177587_1_)
{
if (p_177587_1_ == null)
{
return false;
}
else
{
ModelBlock modelblock = p_177587_1_.getRootModel();
return modelblock == MODEL_ENTITY;
}
}
private void makeItemModels()
{
for (ResourceLocation resourcelocation : this.itemLocations.values())
{
ModelBlock modelblock = this.models.get(resourcelocation);
if (this.hasItemModel(modelblock))
{
ModelBlock modelblock1 = this.makeItemModel(modelblock);
if (modelblock1 != null)
{
modelblock1.name = resourcelocation.toString();
}
this.models.put(resourcelocation, modelblock1);
}
else if (this.isCustomRenderer(modelblock))
{
this.models.put(resourcelocation, modelblock);
}
}
for (TextureAtlasSprite textureatlassprite : this.sprites.values())
{
if (!textureatlassprite.hasAnimationMetadata())
{
textureatlassprite.clearFramesTextureData();
}
}
}
protected ModelBlock makeItemModel(ModelBlock p_177582_1_)
{
return this.itemModelGenerator.makeItemModel(this.textureMap, p_177582_1_);
}
static
{
BUILT_IN_MODELS.put("missing", MISSING_MODEL_MESH);
MODEL_GENERATED.name = "generation marker";
MODEL_ENTITY.name = "block entity marker";
}
protected void registerMultipartVariant(ModelBlockDefinition definition, Collection<ModelResourceLocation> locations)
{
this.multipartVariantMap.put(definition, locations);
}
private static Map<net.minecraftforge.registries.IRegistryDelegate<Item>, Set<String>> customVariantNames = Maps.newHashMap();
public static void registerItemVariants(Item item, ResourceLocation... names)
{
if (!customVariantNames.containsKey(item.delegate))
{
customVariantNames.put(item.delegate, Sets.<String>newHashSet());
}
for(ResourceLocation name : names)
{
customVariantNames.get(item.delegate).add(name.toString());
}
}
}

View File

@@ -0,0 +1,327 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.io.Reader;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class ModelBlock
{
private static final Logger LOGGER = LogManager.getLogger();
@VisibleForTesting
static final Gson SERIALIZER = (new GsonBuilder()).registerTypeAdapter(ModelBlock.class, new ModelBlock.Deserializer()).registerTypeAdapter(BlockPart.class, new BlockPart.Deserializer()).registerTypeAdapter(BlockPartFace.class, new BlockPartFace.Deserializer()).registerTypeAdapter(BlockFaceUV.class, new BlockFaceUV.Deserializer()).registerTypeAdapter(ItemTransformVec3f.class, new ItemTransformVec3f.Deserializer()).registerTypeAdapter(ItemCameraTransforms.class, new ItemCameraTransforms.Deserializer()).registerTypeAdapter(ItemOverride.class, new ItemOverride.Deserializer()).create();
private final List<BlockPart> elements;
private final boolean gui3d;
public final boolean ambientOcclusion;
private final ItemCameraTransforms cameraTransforms;
private final List<ItemOverride> overrides;
public String name = "";
@VisibleForTesting
public final Map<String, String> textures;
@VisibleForTesting
public ModelBlock parent;
@VisibleForTesting
protected ResourceLocation parentLocation;
public static ModelBlock deserialize(Reader readerIn)
{
return (ModelBlock)JsonUtils.gsonDeserialize(SERIALIZER, readerIn, ModelBlock.class, false);
}
public static ModelBlock deserialize(String jsonString)
{
return deserialize(new StringReader(jsonString));
}
public ModelBlock(@Nullable ResourceLocation parentLocationIn, List<BlockPart> elementsIn, Map<String, String> texturesIn, boolean ambientOcclusionIn, boolean gui3dIn, ItemCameraTransforms cameraTransformsIn, List<ItemOverride> overridesIn)
{
this.elements = elementsIn;
this.ambientOcclusion = ambientOcclusionIn;
this.gui3d = gui3dIn;
this.textures = texturesIn;
this.parentLocation = parentLocationIn;
this.cameraTransforms = cameraTransformsIn;
this.overrides = overridesIn;
}
public List<BlockPart> getElements()
{
return this.elements.isEmpty() && this.hasParent() ? this.parent.getElements() : this.elements;
}
private boolean hasParent()
{
return this.parent != null;
}
public boolean isAmbientOcclusion()
{
return this.hasParent() ? this.parent.isAmbientOcclusion() : this.ambientOcclusion;
}
public boolean isGui3d()
{
return this.gui3d;
}
public boolean isResolved()
{
return this.parentLocation == null || this.parent != null && this.parent.isResolved();
}
public void getParentFromMap(Map<ResourceLocation, ModelBlock> p_178299_1_)
{
if (this.parentLocation != null)
{
this.parent = p_178299_1_.get(this.parentLocation);
}
}
public Collection<ResourceLocation> getOverrideLocations()
{
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
for (ItemOverride itemoverride : this.overrides)
{
set.add(itemoverride.getLocation());
}
return set;
}
public List<ItemOverride> getOverrides()
{
return this.overrides;
}
public ItemOverrideList createOverrides()
{
return this.overrides.isEmpty() ? ItemOverrideList.NONE : new ItemOverrideList(this.overrides);
}
public boolean isTexturePresent(String textureName)
{
return !"missingno".equals(this.resolveTextureName(textureName));
}
public String resolveTextureName(String textureName)
{
if (!this.startsWithHash(textureName))
{
textureName = '#' + textureName;
}
return this.resolveTextureName(textureName, new ModelBlock.Bookkeep(this));
}
private String resolveTextureName(String textureName, ModelBlock.Bookkeep p_178302_2_)
{
if (this.startsWithHash(textureName))
{
if (this == p_178302_2_.modelExt)
{
LOGGER.warn("Unable to resolve texture due to upward reference: {} in {}", textureName, this.name);
return "missingno";
}
else
{
String s = this.textures.get(textureName.substring(1));
if (s == null && this.hasParent())
{
s = this.parent.resolveTextureName(textureName, p_178302_2_);
}
p_178302_2_.modelExt = this;
if (s != null && this.startsWithHash(s))
{
s = p_178302_2_.model.resolveTextureName(s, p_178302_2_);
}
return s != null && !this.startsWithHash(s) ? s : "missingno";
}
}
else
{
return textureName;
}
}
private boolean startsWithHash(String hash)
{
return hash.charAt(0) == '#';
}
@Nullable
public ResourceLocation getParentLocation()
{
return this.parentLocation;
}
public ModelBlock getRootModel()
{
return this.hasParent() ? this.parent.getRootModel() : this;
}
public ItemCameraTransforms getAllTransforms()
{
ItemTransformVec3f itemtransformvec3f = this.getTransform(ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND);
ItemTransformVec3f itemtransformvec3f1 = this.getTransform(ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND);
ItemTransformVec3f itemtransformvec3f2 = this.getTransform(ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND);
ItemTransformVec3f itemtransformvec3f3 = this.getTransform(ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND);
ItemTransformVec3f itemtransformvec3f4 = this.getTransform(ItemCameraTransforms.TransformType.HEAD);
ItemTransformVec3f itemtransformvec3f5 = this.getTransform(ItemCameraTransforms.TransformType.GUI);
ItemTransformVec3f itemtransformvec3f6 = this.getTransform(ItemCameraTransforms.TransformType.GROUND);
ItemTransformVec3f itemtransformvec3f7 = this.getTransform(ItemCameraTransforms.TransformType.FIXED);
return new ItemCameraTransforms(itemtransformvec3f, itemtransformvec3f1, itemtransformvec3f2, itemtransformvec3f3, itemtransformvec3f4, itemtransformvec3f5, itemtransformvec3f6, itemtransformvec3f7);
}
private ItemTransformVec3f getTransform(ItemCameraTransforms.TransformType type)
{
return this.parent != null && !this.cameraTransforms.hasCustomTransform(type) ? this.parent.getTransform(type) : this.cameraTransforms.getTransform(type);
}
public static void checkModelHierarchy(Map<ResourceLocation, ModelBlock> p_178312_0_)
{
for (ModelBlock modelblock : p_178312_0_.values())
{
try
{
ModelBlock modelblock1 = modelblock.parent;
for (ModelBlock modelblock2 = modelblock1.parent; modelblock1 != modelblock2; modelblock2 = modelblock2.parent.parent)
{
modelblock1 = modelblock1.parent;
}
throw new ModelBlock.LoopException();
}
catch (NullPointerException var5)
{
;
}
}
}
@SideOnly(Side.CLIENT)
static final class Bookkeep
{
public final ModelBlock model;
public ModelBlock modelExt;
private Bookkeep(ModelBlock modelIn)
{
this.model = modelIn;
}
}
@SideOnly(Side.CLIENT)
public static class Deserializer implements JsonDeserializer<ModelBlock>
{
public ModelBlock deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
List<BlockPart> list = this.getModelElements(p_deserialize_3_, jsonobject);
String s = this.getParent(jsonobject);
Map<String, String> map = this.getTextures(jsonobject);
boolean flag = this.getAmbientOcclusionEnabled(jsonobject);
ItemCameraTransforms itemcameratransforms = ItemCameraTransforms.DEFAULT;
if (jsonobject.has("display"))
{
JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonobject, "display");
itemcameratransforms = (ItemCameraTransforms)p_deserialize_3_.deserialize(jsonobject1, ItemCameraTransforms.class);
}
List<ItemOverride> list1 = this.getItemOverrides(p_deserialize_3_, jsonobject);
ResourceLocation resourcelocation = s.isEmpty() ? null : new ResourceLocation(s);
return new ModelBlock(resourcelocation, list, map, flag, true, itemcameratransforms, list1);
}
protected List<ItemOverride> getItemOverrides(JsonDeserializationContext deserializationContext, JsonObject object)
{
List<ItemOverride> list = Lists.<ItemOverride>newArrayList();
if (object.has("overrides"))
{
for (JsonElement jsonelement : JsonUtils.getJsonArray(object, "overrides"))
{
list.add((ItemOverride)deserializationContext.deserialize(jsonelement, ItemOverride.class));
}
}
return list;
}
private Map<String, String> getTextures(JsonObject object)
{
Map<String, String> map = Maps.<String, String>newHashMap();
if (object.has("textures"))
{
JsonObject jsonobject = object.getAsJsonObject("textures");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
map.put(entry.getKey(), ((JsonElement)entry.getValue()).getAsString());
}
}
return map;
}
private String getParent(JsonObject object)
{
return JsonUtils.getString(object, "parent", "");
}
protected boolean getAmbientOcclusionEnabled(JsonObject object)
{
return JsonUtils.getBoolean(object, "ambientocclusion", true);
}
protected List<BlockPart> getModelElements(JsonDeserializationContext deserializationContext, JsonObject object)
{
List<BlockPart> list = Lists.<BlockPart>newArrayList();
if (object.has("elements"))
{
for (JsonElement jsonelement : JsonUtils.getJsonArray(object, "elements"))
{
list.add((BlockPart)deserializationContext.deserialize(jsonelement, BlockPart.class));
}
}
return list;
}
}
@SideOnly(Side.CLIENT)
public static class LoopException extends RuntimeException
{
}
}

View File

@@ -0,0 +1,195 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.io.Reader;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.client.renderer.block.model.multipart.Multipart;
import net.minecraft.client.renderer.block.model.multipart.Selector;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelBlockDefinition
{
@VisibleForTesting
static final Gson GSON = (new GsonBuilder()).registerTypeAdapter(ModelBlockDefinition.class, new ModelBlockDefinition.Deserializer()).registerTypeAdapter(Variant.class, new Variant.Deserializer()).registerTypeAdapter(VariantList.class, new VariantList.Deserializer()).registerTypeAdapter(Multipart.class, new Multipart.Deserializer()).registerTypeAdapter(Selector.class, new Selector.Deserializer()).create();
private final Map<String, VariantList> mapVariants = Maps.<String, VariantList>newHashMap();
private Multipart multipart;
@Deprecated
public static ModelBlockDefinition parseFromReader(Reader reader)
{
return parseFromReader(reader, null);
}
public static ModelBlockDefinition parseFromReader(Reader reader, net.minecraft.util.ResourceLocation location) {
return net.minecraftforge.client.model.BlockStateLoader.load(reader, location, GSON);
}
public ModelBlockDefinition(Map<String, VariantList> variants, Multipart multipartIn)
{
this.multipart = multipartIn;
this.mapVariants.putAll(variants);
}
public ModelBlockDefinition(List<ModelBlockDefinition> p_i46222_1_)
{
ModelBlockDefinition modelblockdefinition = null;
for (ModelBlockDefinition modelblockdefinition1 : p_i46222_1_)
{
if (modelblockdefinition1.hasMultipartData())
{
this.mapVariants.clear();
modelblockdefinition = modelblockdefinition1;
}
this.mapVariants.putAll(modelblockdefinition1.mapVariants);
}
if (modelblockdefinition != null)
{
this.multipart = modelblockdefinition.multipart;
}
}
public boolean hasVariant(String p_188000_1_)
{
return this.mapVariants.get(p_188000_1_) != null;
}
public VariantList getVariant(String p_188004_1_)
{
VariantList variantlist = this.mapVariants.get(p_188004_1_);
if (variantlist == null)
{
throw new ModelBlockDefinition.MissingVariantException();
}
else
{
return variantlist;
}
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else
{
if (p_equals_1_ instanceof ModelBlockDefinition)
{
ModelBlockDefinition modelblockdefinition = (ModelBlockDefinition)p_equals_1_;
if (this.mapVariants.equals(modelblockdefinition.mapVariants))
{
return this.hasMultipartData() ? this.multipart.equals(modelblockdefinition.multipart) : !modelblockdefinition.hasMultipartData();
}
}
return false;
}
}
public int hashCode()
{
return 31 * this.mapVariants.hashCode() + (this.hasMultipartData() ? this.multipart.hashCode() : 0);
}
public Set<VariantList> getMultipartVariants()
{
Set<VariantList> set = Sets.newHashSet(this.mapVariants.values());
if (this.hasMultipartData())
{
set.addAll(this.multipart.getVariants());
}
return set;
}
public boolean hasMultipartData()
{
return this.multipart != null;
}
public Multipart getMultipartData()
{
return this.multipart;
}
@SideOnly(Side.CLIENT)
public static class Deserializer implements JsonDeserializer<ModelBlockDefinition>
{
public ModelBlockDefinition deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
Map<String, VariantList> map = this.parseMapVariants(p_deserialize_3_, jsonobject);
Multipart multipart = this.parseMultipart(p_deserialize_3_, jsonobject);
if (!map.isEmpty() || multipart != null && !multipart.getVariants().isEmpty())
{
return new ModelBlockDefinition(map, multipart);
}
else
{
throw new JsonParseException("Neither 'variants' nor 'multipart' found");
}
}
protected Map<String, VariantList> parseMapVariants(JsonDeserializationContext deserializationContext, JsonObject object)
{
Map<String, VariantList> map = Maps.<String, VariantList>newHashMap();
if (object.has("variants"))
{
JsonObject jsonobject = JsonUtils.getJsonObject(object, "variants");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
map.put(entry.getKey(), (VariantList)deserializationContext.deserialize(entry.getValue(), VariantList.class));
}
}
return map;
}
@Nullable
protected Multipart parseMultipart(JsonDeserializationContext deserializationContext, JsonObject object)
{
if (!object.has("multipart"))
{
return null;
}
else
{
JsonArray jsonarray = JsonUtils.getJsonArray(object, "multipart");
return (Multipart)deserializationContext.deserialize(jsonarray, Multipart.class);
}
}
}
@SideOnly(Side.CLIENT)
public class MissingVariantException extends RuntimeException
{
}
}

View File

@@ -0,0 +1,61 @@
package net.minecraft.client.renderer.block.model;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.util.registry.IRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelManager implements IResourceManagerReloadListener
{
private IRegistry<ModelResourceLocation, IBakedModel> modelRegistry;
private final TextureMap texMap;
private final BlockModelShapes modelProvider;
private IBakedModel defaultModel;
public ModelManager(TextureMap textures)
{
this.texMap = textures;
this.modelProvider = new BlockModelShapes(this);
}
public void onResourceManagerReload(IResourceManager resourceManager)
{
net.minecraftforge.client.model.ModelLoader modelbakery = new net.minecraftforge.client.model.ModelLoader(resourceManager, this.texMap, this.modelProvider);
this.modelRegistry = modelbakery.setupModelRegistry();
this.defaultModel = this.modelRegistry.getObject(ModelBakery.MODEL_MISSING);
net.minecraftforge.client.ForgeHooksClient.onModelBake(this, this.modelRegistry, modelbakery);
this.modelProvider.reloadModels();
}
public IBakedModel getModel(ModelResourceLocation modelLocation)
{
if (modelLocation == null)
{
return this.defaultModel;
}
else
{
IBakedModel ibakedmodel = this.modelRegistry.getObject(modelLocation);
return ibakedmodel == null ? this.defaultModel : ibakedmodel;
}
}
public IBakedModel getMissingModel()
{
return this.defaultModel;
}
public TextureMap getTextureMap()
{
return this.texMap;
}
public BlockModelShapes getBlockModelShapes()
{
return this.modelProvider;
}
}

View File

@@ -0,0 +1,83 @@
package net.minecraft.client.renderer.block.model;
import java.util.Locale;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.lang3.StringUtils;
public class ModelResourceLocation extends ResourceLocation
{
private final String variant;
protected ModelResourceLocation(int unused, String... resourceName)
{
super(0, resourceName[0], resourceName[1]);
this.variant = StringUtils.isEmpty(resourceName[2]) ? "normal" : resourceName[2].toLowerCase(Locale.ROOT);
}
public ModelResourceLocation(String pathIn)
{
this(0, parsePathString(pathIn));
}
public ModelResourceLocation(ResourceLocation location, String variantIn)
{
this(location.toString(), variantIn);
}
public ModelResourceLocation(String location, String variantIn)
{
this(0, parsePathString(location + '#' + (variantIn == null ? "normal" : variantIn)));
}
protected static String[] parsePathString(String pathIn)
{
String[] astring = new String[] {null, pathIn, null};
int i = pathIn.indexOf(35);
String s = pathIn;
if (i >= 0)
{
astring[2] = pathIn.substring(i + 1, pathIn.length());
if (i > 1)
{
s = pathIn.substring(0, i);
}
}
System.arraycopy(ResourceLocation.splitObjectName(s), 0, astring, 0, 2);
return astring;
}
public String getVariant()
{
return this.variant;
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (p_equals_1_ instanceof ModelResourceLocation && super.equals(p_equals_1_))
{
ModelResourceLocation modelresourcelocation = (ModelResourceLocation)p_equals_1_;
return this.variant.equals(modelresourcelocation.variant);
}
else
{
return false;
}
}
public int hashCode()
{
return 31 * super.hashCode() + this.variant.hashCode();
}
public String toString()
{
return super.toString() + '#' + this.variant;
}
}

View File

@@ -0,0 +1,124 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.collect.Maps;
import java.util.Map;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
@SideOnly(Side.CLIENT)
public enum ModelRotation implements net.minecraftforge.common.model.IModelState, net.minecraftforge.common.model.ITransformation
{
X0_Y0(0, 0),
X0_Y90(0, 90),
X0_Y180(0, 180),
X0_Y270(0, 270),
X90_Y0(90, 0),
X90_Y90(90, 90),
X90_Y180(90, 180),
X90_Y270(90, 270),
X180_Y0(180, 0),
X180_Y90(180, 90),
X180_Y180(180, 180),
X180_Y270(180, 270),
X270_Y0(270, 0),
X270_Y90(270, 90),
X270_Y180(270, 180),
X270_Y270(270, 270);
private static final Map<Integer, ModelRotation> MAP_ROTATIONS = Maps.<Integer, ModelRotation>newHashMap();
private final int combinedXY;
private final Matrix4f matrix4d;
private final int quartersX;
private final int quartersY;
private static int combineXY(int p_177521_0_, int p_177521_1_)
{
return p_177521_0_ * 360 + p_177521_1_;
}
private ModelRotation(int x, int y)
{
this.combinedXY = combineXY(x, y);
this.matrix4d = new Matrix4f();
Matrix4f matrix4f = new Matrix4f();
matrix4f.setIdentity();
Matrix4f.rotate((float)(-x) * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), matrix4f, matrix4f);
this.quartersX = MathHelper.abs(x / 90);
Matrix4f matrix4f1 = new Matrix4f();
matrix4f1.setIdentity();
Matrix4f.rotate((float)(-y) * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), matrix4f1, matrix4f1);
this.quartersY = MathHelper.abs(y / 90);
Matrix4f.mul(matrix4f1, matrix4f, this.matrix4d);
}
public Matrix4f getMatrix4d()
{
return this.matrix4d;
}
public EnumFacing rotateFace(EnumFacing facing)
{
EnumFacing enumfacing = facing;
for (int i = 0; i < this.quartersX; ++i)
{
enumfacing = enumfacing.rotateAround(EnumFacing.Axis.X);
}
if (enumfacing.getAxis() != EnumFacing.Axis.Y)
{
for (int j = 0; j < this.quartersY; ++j)
{
enumfacing = enumfacing.rotateAround(EnumFacing.Axis.Y);
}
}
return enumfacing;
}
public int rotateVertex(EnumFacing facing, int vertexIndex)
{
int i = vertexIndex;
if (facing.getAxis() == EnumFacing.Axis.X)
{
i = (vertexIndex + this.quartersX) % 4;
}
EnumFacing enumfacing = facing;
for (int j = 0; j < this.quartersX; ++j)
{
enumfacing = enumfacing.rotateAround(EnumFacing.Axis.X);
}
if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
i = (i + this.quartersY) % 4;
}
return i;
}
public static ModelRotation getModelRotation(int x, int y)
{
return MAP_ROTATIONS.get(Integer.valueOf(combineXY(MathHelper.normalizeAngle(x, 360), MathHelper.normalizeAngle(y, 360))));
}
static
{
for (ModelRotation modelrotation : values())
{
MAP_ROTATIONS.put(Integer.valueOf(modelrotation.combinedXY), modelrotation);
}
}
public java.util.Optional<net.minecraftforge.common.model.TRSRTransformation> apply(java.util.Optional<? extends net.minecraftforge.common.model.IModelPart> part) { return net.minecraftforge.client.ForgeHooksClient.applyTransform(this, part); }
public javax.vecmath.Matrix4f getMatrix() { return net.minecraftforge.common.model.TRSRTransformation.from(this).getMatrix(); }
public EnumFacing rotate(EnumFacing facing) { return rotateFace(facing); }
public int rotate(EnumFacing facing, int vertexIndex) { return rotateVertex(facing, vertexIndex); }
}

View File

@@ -0,0 +1,100 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class MultipartBakedModel implements IBakedModel
{
private final Map<Predicate<IBlockState>, IBakedModel> selectors;
protected final boolean ambientOcclusion;
protected final boolean gui3D;
protected final TextureAtlasSprite particleTexture;
protected final ItemCameraTransforms cameraTransforms;
protected final ItemOverrideList overrides;
public MultipartBakedModel(Map<Predicate<IBlockState>, IBakedModel> selectorsIn)
{
this.selectors = selectorsIn;
IBakedModel ibakedmodel = selectorsIn.values().iterator().next();
this.ambientOcclusion = ibakedmodel.isAmbientOcclusion();
this.gui3D = ibakedmodel.isGui3d();
this.particleTexture = ibakedmodel.getParticleTexture();
this.cameraTransforms = ibakedmodel.getItemCameraTransforms();
this.overrides = ibakedmodel.getOverrides();
}
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
List<BakedQuad> list = Lists.<BakedQuad>newArrayList();
if (state != null)
{
for (Entry<Predicate<IBlockState>, IBakedModel> entry : this.selectors.entrySet())
{
if (((Predicate)entry.getKey()).apply(state))
{
list.addAll((entry.getValue()).getQuads(state, side, rand++));
}
}
}
return list;
}
public boolean isAmbientOcclusion()
{
return this.ambientOcclusion;
}
public boolean isGui3d()
{
return this.gui3D;
}
public boolean isBuiltInRenderer()
{
return false;
}
public TextureAtlasSprite getParticleTexture()
{
return this.particleTexture;
}
public ItemCameraTransforms getItemCameraTransforms()
{
return this.cameraTransforms;
}
public ItemOverrideList getOverrides()
{
return this.overrides;
}
@SideOnly(Side.CLIENT)
public static class Builder
{
private final Map<Predicate<IBlockState>, IBakedModel> builderSelectors = Maps.<Predicate<IBlockState>, IBakedModel>newLinkedHashMap();
public void putModel(Predicate<IBlockState> predicate, IBakedModel model)
{
this.builderSelectors.put(predicate, model);
}
public IBakedModel makeMultipartModel()
{
return new MultipartBakedModel(this.builderSelectors);
}
}
}

View File

@@ -0,0 +1,165 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class SimpleBakedModel implements IBakedModel
{
protected final List<BakedQuad> generalQuads;
protected final Map<EnumFacing, List<BakedQuad>> faceQuads;
protected final boolean ambientOcclusion;
protected final boolean gui3d;
protected final TextureAtlasSprite texture;
protected final ItemCameraTransforms cameraTransforms;
protected final ItemOverrideList itemOverrideList;
public SimpleBakedModel(List<BakedQuad> generalQuadsIn, Map<EnumFacing, List<BakedQuad>> faceQuadsIn, boolean ambientOcclusionIn, boolean gui3dIn, TextureAtlasSprite textureIn, ItemCameraTransforms cameraTransformsIn, ItemOverrideList itemOverrideListIn)
{
this.generalQuads = generalQuadsIn;
this.faceQuads = faceQuadsIn;
this.ambientOcclusion = ambientOcclusionIn;
this.gui3d = gui3dIn;
this.texture = textureIn;
this.cameraTransforms = cameraTransformsIn;
this.itemOverrideList = itemOverrideListIn;
}
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
return side == null ? this.generalQuads : (List)this.faceQuads.get(side);
}
public boolean isAmbientOcclusion()
{
return this.ambientOcclusion;
}
public boolean isGui3d()
{
return this.gui3d;
}
public boolean isBuiltInRenderer()
{
return false;
}
public TextureAtlasSprite getParticleTexture()
{
return this.texture;
}
public ItemCameraTransforms getItemCameraTransforms()
{
return this.cameraTransforms;
}
public ItemOverrideList getOverrides()
{
return this.itemOverrideList;
}
@SideOnly(Side.CLIENT)
public static class Builder
{
private final List<BakedQuad> builderGeneralQuads;
private final Map<EnumFacing, List<BakedQuad>> builderFaceQuads;
private final ItemOverrideList builderItemOverrideList;
private final boolean builderAmbientOcclusion;
private TextureAtlasSprite builderTexture;
private final boolean builderGui3d;
private final ItemCameraTransforms builderCameraTransforms;
public Builder(ModelBlock model, ItemOverrideList overrides)
{
this(model.isAmbientOcclusion(), model.isGui3d(), model.getAllTransforms(), overrides);
}
public Builder(IBlockState state, IBakedModel model, TextureAtlasSprite texture, BlockPos pos)
{
this(model.isAmbientOcclusion(state), model.isGui3d(), model.getItemCameraTransforms(), model.getOverrides());
this.builderTexture = model.getParticleTexture();
long i = MathHelper.getPositionRandom(pos);
for (EnumFacing enumfacing : EnumFacing.values())
{
this.addFaceQuads(state, model, texture, enumfacing, i);
}
this.addGeneralQuads(state, model, texture, i);
}
private Builder(boolean ambientOcclusion, boolean gui3d, ItemCameraTransforms transforms, ItemOverrideList overrides)
{
this.builderGeneralQuads = Lists.<BakedQuad>newArrayList();
this.builderFaceQuads = Maps.newEnumMap(EnumFacing.class);
for (EnumFacing enumfacing : EnumFacing.values())
{
this.builderFaceQuads.put(enumfacing, Lists.newArrayList());
}
this.builderItemOverrideList = overrides;
this.builderAmbientOcclusion = ambientOcclusion;
this.builderGui3d = gui3d;
this.builderCameraTransforms = transforms;
}
private void addFaceQuads(IBlockState p_188644_1_, IBakedModel p_188644_2_, TextureAtlasSprite p_188644_3_, EnumFacing p_188644_4_, long p_188644_5_)
{
for (BakedQuad bakedquad : p_188644_2_.getQuads(p_188644_1_, p_188644_4_, p_188644_5_))
{
this.addFaceQuad(p_188644_4_, new BakedQuadRetextured(bakedquad, p_188644_3_));
}
}
private void addGeneralQuads(IBlockState p_188645_1_, IBakedModel p_188645_2_, TextureAtlasSprite p_188645_3_, long p_188645_4_)
{
for (BakedQuad bakedquad : p_188645_2_.getQuads(p_188645_1_, (EnumFacing)null, p_188645_4_))
{
this.addGeneralQuad(new BakedQuadRetextured(bakedquad, p_188645_3_));
}
}
public SimpleBakedModel.Builder addFaceQuad(EnumFacing facing, BakedQuad quad)
{
(this.builderFaceQuads.get(facing)).add(quad);
return this;
}
public SimpleBakedModel.Builder addGeneralQuad(BakedQuad quad)
{
this.builderGeneralQuads.add(quad);
return this;
}
public SimpleBakedModel.Builder setTexture(TextureAtlasSprite texture)
{
this.builderTexture = texture;
return this;
}
public IBakedModel makeBakedModel()
{
if (this.builderTexture == null)
{
throw new RuntimeException("Missing particle!");
}
else
{
return new SimpleBakedModel(this.builderGeneralQuads, this.builderFaceQuads, this.builderAmbientOcclusion, this.builderGui3d, this.builderTexture, this.builderCameraTransforms, this.builderItemOverrideList);
}
}
}
}

View File

@@ -0,0 +1,152 @@
package net.minecraft.client.renderer.block.model;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Variant implements net.minecraftforge.client.model.ISmartVariant
{
private final ResourceLocation modelLocation;
private final ModelRotation rotation;
private final boolean uvLock;
private final int weight;
public Variant(ResourceLocation modelLocationIn, ModelRotation rotationIn, boolean uvLockIn, int weightIn)
{
this.modelLocation = modelLocationIn;
this.rotation = rotationIn;
this.uvLock = uvLockIn;
this.weight = weightIn;
}
public ResourceLocation getModelLocation()
{
return this.modelLocation;
}
@Deprecated
public ModelRotation getRotation()
{
return this.rotation;
}
public net.minecraftforge.common.model.IModelState getState()
{
return this.rotation;
}
public boolean isUvLock()
{
return this.uvLock;
}
public int getWeight()
{
return this.weight;
}
public String toString()
{
return "Variant{modelLocation=" + this.modelLocation + ", rotation=" + this.rotation + ", uvLock=" + this.uvLock + ", weight=" + this.weight + '}';
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (!(p_equals_1_ instanceof Variant))
{
return false;
}
else
{
Variant variant = (Variant)p_equals_1_;
return this.modelLocation.equals(variant.modelLocation) && this.rotation == variant.rotation && this.uvLock == variant.uvLock && this.weight == variant.weight;
}
}
public int hashCode()
{
int i = this.modelLocation.hashCode();
i = 31 * i + this.rotation.hashCode();
i = 31 * i + Boolean.valueOf(this.uvLock).hashCode();
i = 31 * i + this.weight;
return i;
}
@SideOnly(Side.CLIENT)
public static class Deserializer implements JsonDeserializer<Variant>
{
public Variant deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
String s = this.getStringModel(jsonobject);
ModelRotation modelrotation = this.parseModelRotation(jsonobject);
boolean flag = this.parseUvLock(jsonobject);
int i = this.parseWeight(jsonobject);
return new Variant(this.getResourceLocationBlock(s), modelrotation, flag, i);
}
private ResourceLocation getResourceLocationBlock(String p_188041_1_)
{
ResourceLocation resourcelocation = new ResourceLocation(p_188041_1_);
resourcelocation = new ResourceLocation(resourcelocation.getResourceDomain(), "block/" + resourcelocation.getResourcePath());
return resourcelocation;
}
private boolean parseUvLock(JsonObject json)
{
return JsonUtils.getBoolean(json, "uvlock", false);
}
protected ModelRotation parseModelRotation(JsonObject json)
{
int i = JsonUtils.getInt(json, "x", 0);
int j = JsonUtils.getInt(json, "y", 0);
ModelRotation modelrotation = ModelRotation.getModelRotation(i, j);
if (modelrotation == null)
{
throw new JsonParseException("Invalid BlockModelRotation x: " + i + ", y: " + j);
}
else
{
return modelrotation;
}
}
protected String getStringModel(JsonObject json)
{
return JsonUtils.getString(json, "model");
}
protected int parseWeight(JsonObject json)
{
int i = JsonUtils.getInt(json, "weight", 1);
if (i < 1)
{
throw new JsonParseException("Invalid weight " + i + " found, expected integer >= 1");
}
else
{
return i;
}
}
}
public net.minecraftforge.client.model.IModel process(net.minecraftforge.client.model.IModel base)
{
return base.uvlock(isUvLock());
}
}

View File

@@ -0,0 +1,80 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.List;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class VariantList
{
private final List<Variant> variantList;
public VariantList(List<Variant> variantListIn)
{
this.variantList = variantListIn;
}
public List<Variant> getVariantList()
{
return this.variantList;
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (p_equals_1_ instanceof VariantList)
{
VariantList variantlist = (VariantList)p_equals_1_;
return this.variantList.equals(variantlist.variantList);
}
else
{
return false;
}
}
public int hashCode()
{
return this.variantList.hashCode();
}
@SideOnly(Side.CLIENT)
public static class Deserializer implements JsonDeserializer<VariantList>
{
public VariantList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
List<Variant> list = Lists.<Variant>newArrayList();
if (p_deserialize_1_.isJsonArray())
{
JsonArray jsonarray = p_deserialize_1_.getAsJsonArray();
if (jsonarray.size() == 0)
{
throw new JsonParseException("Empty variant array");
}
for (JsonElement jsonelement : jsonarray)
{
list.add((Variant)p_deserialize_3_.deserialize(jsonelement, Variant.class));
}
}
else
{
list.add((Variant)p_deserialize_3_.deserialize(p_deserialize_1_, Variant.class));
}
return new VariantList(list);
}
}
}

View File

@@ -0,0 +1,115 @@
package net.minecraft.client.renderer.block.model;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.WeightedRandom;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class WeightedBakedModel implements IBakedModel
{
private final int totalWeight;
private final List<WeightedBakedModel.WeightedModel> models;
private final IBakedModel baseModel;
public WeightedBakedModel(List<WeightedBakedModel.WeightedModel> modelsIn)
{
this.models = modelsIn;
this.totalWeight = WeightedRandom.getTotalWeight(modelsIn);
this.baseModel = (modelsIn.get(0)).model;
}
private IBakedModel getRandomModel(long p_188627_1_)
{
return ((WeightedBakedModel.WeightedModel)WeightedRandom.getRandomItem(this.models, Math.abs((int)p_188627_1_ >> 16) % this.totalWeight)).model;
}
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
{
return this.getRandomModel(rand).getQuads(state, side, rand);
}
public boolean isAmbientOcclusion()
{
return this.baseModel.isAmbientOcclusion();
}
public boolean isAmbientOcclusion(IBlockState state) { return this.baseModel.isAmbientOcclusion(state); }
public boolean isGui3d()
{
return this.baseModel.isGui3d();
}
public boolean isBuiltInRenderer()
{
return this.baseModel.isBuiltInRenderer();
}
public TextureAtlasSprite getParticleTexture()
{
return this.baseModel.getParticleTexture();
}
public ItemCameraTransforms getItemCameraTransforms()
{
return this.baseModel.getItemCameraTransforms();
}
public ItemOverrideList getOverrides()
{
return this.baseModel.getOverrides();
}
@SideOnly(Side.CLIENT)
public static class Builder
{
private final List<WeightedBakedModel.WeightedModel> listItems = Lists.<WeightedBakedModel.WeightedModel>newArrayList();
public WeightedBakedModel.Builder add(IBakedModel model, int weight)
{
this.listItems.add(new WeightedBakedModel.WeightedModel(model, weight));
return this;
}
public WeightedBakedModel build()
{
Collections.sort(this.listItems);
return new WeightedBakedModel(this.listItems);
}
public IBakedModel first()
{
return (this.listItems.get(0)).model;
}
}
@SideOnly(Side.CLIENT)
static class WeightedModel extends WeightedRandom.Item implements Comparable<WeightedBakedModel.WeightedModel>
{
protected final IBakedModel model;
public WeightedModel(IBakedModel modelIn, int itemWeightIn)
{
super(itemWeightIn);
this.model = modelIn;
}
public int compareTo(WeightedBakedModel.WeightedModel p_compareTo_1_)
{
return ComparisonChain.start().compare(p_compareTo_1_.itemWeight, this.itemWeight).result();
}
public String toString()
{
return "MyWeighedRandomItem{weight=" + this.itemWeight + ", model=" + this.model + '}';
}
}
}

View File

@@ -0,0 +1,34 @@
package net.minecraft.client.renderer.block.model.multipart;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import javax.annotation.Nullable;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ConditionAnd implements ICondition
{
private final Iterable<ICondition> conditions;
public ConditionAnd(Iterable<ICondition> conditionsIn)
{
this.conditions = conditionsIn;
}
public Predicate<IBlockState> getPredicate(final BlockStateContainer blockState)
{
return Predicates.and(Iterables.transform(this.conditions, new Function<ICondition, Predicate<IBlockState>>()
{
@Nullable
public Predicate<IBlockState> apply(@Nullable ICondition p_apply_1_)
{
return p_apply_1_ == null ? null : p_apply_1_.getPredicate(blockState);
}
}));
}
}

View File

@@ -0,0 +1,34 @@
package net.minecraft.client.renderer.block.model.multipart;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import javax.annotation.Nullable;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ConditionOr implements ICondition
{
final Iterable<ICondition> conditions;
public ConditionOr(Iterable<ICondition> conditionsIn)
{
this.conditions = conditionsIn;
}
public Predicate<IBlockState> getPredicate(final BlockStateContainer blockState)
{
return Predicates.or(Iterables.transform(this.conditions, new Function<ICondition, Predicate<IBlockState>>()
{
@Nullable
public Predicate<IBlockState> apply(@Nullable ICondition p_apply_1_)
{
return p_apply_1_ == null ? null : p_apply_1_.getPredicate(blockState);
}
}));
}
}

View File

@@ -0,0 +1,104 @@
package net.minecraft.client.renderer.block.model.multipart;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ConditionPropertyValue implements ICondition
{
private static final Splitter SPLITTER = Splitter.on('|').omitEmptyStrings();
private final String key;
private final String value;
public ConditionPropertyValue(String keyIn, String valueIn)
{
this.key = keyIn;
this.value = valueIn;
}
public Predicate<IBlockState> getPredicate(BlockStateContainer blockState)
{
final IProperty<?> iproperty = blockState.getProperty(this.key);
if (iproperty == null)
{
throw new RuntimeException(this.toString() + ": Definition: " + blockState + " has no property: " + this.key);
}
else
{
String s = this.value;
boolean flag = !s.isEmpty() && s.charAt(0) == '!';
if (flag)
{
s = s.substring(1);
}
List<String> list = SPLITTER.splitToList(s);
if (list.isEmpty())
{
throw new RuntimeException(this.toString() + ": has an empty value: " + this.value);
}
else
{
Predicate<IBlockState> predicate;
if (list.size() == 1)
{
predicate = this.makePredicate(iproperty, s);
}
else
{
predicate = Predicates.or(Iterables.transform(list, new Function<String, Predicate<IBlockState>>()
{
@Nullable
public Predicate<IBlockState> apply(@Nullable String p_apply_1_)
{
return ConditionPropertyValue.this.makePredicate(iproperty, p_apply_1_);
}
}));
}
return flag ? Predicates.not(predicate) : predicate;
}
}
}
private Predicate<IBlockState> makePredicate(final IProperty<?> property, String valueIn)
{
final Optional<?> optional = property.parseValue(valueIn);
if (!optional.isPresent())
{
throw new RuntimeException(this.toString() + ": has an unknown value: " + this.value);
}
else
{
return new Predicate<IBlockState>()
{
public boolean apply(@Nullable IBlockState p_apply_1_)
{
return p_apply_1_ != null && p_apply_1_.getValue(property).equals(optional.get());
}
};
}
}
public String toString()
{
return MoreObjects.toStringHelper(this).add("key", this.key).add("value", this.value).toString();
}
}

View File

@@ -0,0 +1,41 @@
package net.minecraft.client.renderer.block.model.multipart;
import com.google.common.base.Predicate;
import javax.annotation.Nullable;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface ICondition
{
ICondition TRUE = new ICondition()
{
public Predicate<IBlockState> getPredicate(BlockStateContainer blockState)
{
return new Predicate<IBlockState>()
{
public boolean apply(@Nullable IBlockState p_apply_1_)
{
return true;
}
};
}
};
ICondition FALSE = new ICondition()
{
public Predicate<IBlockState> getPredicate(BlockStateContainer blockState)
{
return new Predicate<IBlockState>()
{
public boolean apply(@Nullable IBlockState p_apply_1_)
{
return false;
}
};
}
};
Predicate<IBlockState> getPredicate(BlockStateContainer blockState);
}

View File

@@ -0,0 +1,108 @@
package net.minecraft.client.renderer.block.model.multipart;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Set;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.client.renderer.block.model.VariantList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Multipart
{
private final List<Selector> selectors;
private BlockStateContainer stateContainer;
public Multipart(List<Selector> selectorsIn)
{
this.selectors = selectorsIn;
}
public List<Selector> getSelectors()
{
return this.selectors;
}
public Set<VariantList> getVariants()
{
Set<VariantList> set = Sets.<VariantList>newHashSet();
for (Selector selector : this.selectors)
{
set.add(selector.getVariantList());
}
return set;
}
public void setStateContainer(BlockStateContainer stateContainerIn)
{
this.stateContainer = stateContainerIn;
}
public BlockStateContainer getStateContainer()
{
return this.stateContainer;
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else
{
if (p_equals_1_ instanceof Multipart)
{
Multipart multipart = (Multipart)p_equals_1_;
if (this.selectors.equals(multipart.selectors))
{
if (this.stateContainer == null)
{
return multipart.stateContainer == null;
}
return this.stateContainer.equals(multipart.stateContainer);
}
}
return false;
}
}
public int hashCode()
{
return 31 * this.selectors.hashCode() + (this.stateContainer == null ? 0 : this.stateContainer.hashCode());
}
@SideOnly(Side.CLIENT)
public static class Deserializer implements JsonDeserializer<Multipart>
{
public Multipart deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
return new Multipart(this.getSelectors(p_deserialize_3_, p_deserialize_1_.getAsJsonArray()));
}
private List<Selector> getSelectors(JsonDeserializationContext context, JsonArray elements)
{
List<Selector> list = Lists.<Selector>newArrayList();
for (JsonElement jsonelement : elements)
{
list.add((Selector)context.deserialize(jsonelement, Selector.class));
}
return list;
}
}
}

View File

@@ -0,0 +1,145 @@
package net.minecraft.client.renderer.block.model.multipart;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.VariantList;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Selector
{
private final ICondition condition;
private final VariantList variantList;
public Selector(ICondition conditionIn, VariantList variantListIn)
{
if (conditionIn == null)
{
throw new IllegalArgumentException("Missing condition for selector");
}
else if (variantListIn == null)
{
throw new IllegalArgumentException("Missing variant for selector");
}
else
{
this.condition = conditionIn;
this.variantList = variantListIn;
}
}
public VariantList getVariantList()
{
return this.variantList;
}
public Predicate<IBlockState> getPredicate(BlockStateContainer state)
{
return this.condition.getPredicate(state);
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else
{
if (p_equals_1_ instanceof Selector)
{
Selector selector = (Selector)p_equals_1_;
if (this.condition.equals(selector.condition))
{
return this.variantList.equals(selector.variantList);
}
}
return false;
}
}
public int hashCode()
{
return 31 * this.condition.hashCode() + this.variantList.hashCode();
}
@SideOnly(Side.CLIENT)
public static class Deserializer implements JsonDeserializer<Selector>
{
private static final Function<JsonElement, ICondition> FUNCTION_OR_AND = new Function<JsonElement, ICondition>()
{
@Nullable
public ICondition apply(@Nullable JsonElement p_apply_1_)
{
return p_apply_1_ == null ? null : Selector.Deserializer.getOrAndCondition(p_apply_1_.getAsJsonObject());
}
};
private static final Function<Entry<String, JsonElement>, ICondition> FUNCTION_PROPERTY_VALUE = new Function<Entry<String, JsonElement>, ICondition>()
{
@Nullable
public ICondition apply(@Nullable Entry<String, JsonElement> p_apply_1_)
{
return p_apply_1_ == null ? null : Selector.Deserializer.makePropertyValue(p_apply_1_);
}
};
public Selector deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
return new Selector(this.getWhenCondition(jsonobject), (VariantList)p_deserialize_3_.deserialize(jsonobject.get("apply"), VariantList.class));
}
private ICondition getWhenCondition(JsonObject json)
{
return json.has("when") ? getOrAndCondition(JsonUtils.getJsonObject(json, "when")) : ICondition.TRUE;
}
@VisibleForTesting
static ICondition getOrAndCondition(JsonObject json)
{
Set<Entry<String, JsonElement>> set = json.entrySet();
if (set.isEmpty())
{
throw new JsonParseException("No elements found in selector");
}
else if (set.size() == 1)
{
if (json.has("OR"))
{
return new ConditionOr(Iterables.transform(JsonUtils.getJsonArray(json, "OR"), FUNCTION_OR_AND));
}
else
{
return (ICondition)(json.has("AND") ? new ConditionAnd(Iterables.transform(JsonUtils.getJsonArray(json, "AND"), FUNCTION_OR_AND)) : makePropertyValue(set.iterator().next()));
}
}
else
{
return new ConditionAnd(Iterables.transform(set, FUNCTION_PROPERTY_VALUE));
}
}
private static ConditionPropertyValue makePropertyValue(Entry<String, JsonElement> entry)
{
return new ConditionPropertyValue(entry.getKey(), ((JsonElement)entry.getValue()).getAsString());
}
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.client.renderer.block.model.multipart;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.client.renderer.block.model;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,76 @@
package net.minecraft.client.renderer.block.statemap;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BlockStateMapper
{
private final Map<Block, IStateMapper> blockStateMap = Maps.<Block, IStateMapper>newIdentityHashMap();
private final Set<Block> setBuiltInBlocks = Sets.<Block>newIdentityHashSet();
public void registerBlockStateMapper(Block blockIn, IStateMapper stateMapper)
{
this.blockStateMap.put(blockIn, stateMapper);
}
public void registerBuiltInBlocks(Block... blockIn)
{
Collections.addAll(this.setBuiltInBlocks, blockIn);
}
public Map<IBlockState, ModelResourceLocation> putAllStateModelLocations()
{
Map<IBlockState, ModelResourceLocation> map = Maps.<IBlockState, ModelResourceLocation>newIdentityHashMap();
for (Block block : Block.REGISTRY)
{
map.putAll(this.getVariants(block));
}
return map;
}
public Set<ResourceLocation> getBlockstateLocations(Block blockIn)
{
if (this.setBuiltInBlocks.contains(blockIn))
{
return Collections.<ResourceLocation>emptySet();
}
else
{
IStateMapper istatemapper = this.blockStateMap.get(blockIn);
if (istatemapper == null)
{
return Collections.<ResourceLocation>singleton(Block.REGISTRY.getNameForObject(blockIn));
}
else
{
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
for (ModelResourceLocation modelresourcelocation : istatemapper.putStateModelLocations(blockIn).values())
{
set.add(new ResourceLocation(modelresourcelocation.getResourceDomain(), modelresourcelocation.getResourcePath()));
}
return set;
}
}
}
public Map<IBlockState, ModelResourceLocation> getVariants(Block blockIn)
{
return this.setBuiltInBlocks.contains(blockIn) ? Collections.emptyMap() : ((IStateMapper)MoreObjects.firstNonNull(this.blockStateMap.get(blockIn), new DefaultStateMapper())).putStateModelLocations(blockIn);
}
}

View File

@@ -0,0 +1,16 @@
package net.minecraft.client.renderer.block.statemap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class DefaultStateMapper extends StateMapperBase
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
return new ModelResourceLocation(Block.REGISTRY.getNameForObject(state.getBlock()), this.getPropertyString(state.getProperties()));
}
}

View File

@@ -0,0 +1,14 @@
package net.minecraft.client.renderer.block.statemap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IStateMapper
{
Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block blockIn);
}

View File

@@ -0,0 +1,109 @@
package net.minecraft.client.renderer.block.statemap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class StateMap extends StateMapperBase
{
private final IProperty<?> name;
private final String suffix;
private final List < IProperty<? >> ignored;
private StateMap(@Nullable IProperty<?> name, @Nullable String suffix, List < IProperty<? >> ignored)
{
this.name = name;
this.suffix = suffix;
this.ignored = ignored;
}
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
Map < IProperty<?>, Comparable<? >> map = Maps. < IProperty<?>, Comparable<? >> newLinkedHashMap(state.getProperties());
String s;
if (this.name == null)
{
s = ((ResourceLocation)Block.REGISTRY.getNameForObject(state.getBlock())).toString();
}
else
{
s = String.format("%s:%s", Block.REGISTRY.getNameForObject(state.getBlock()).getResourceDomain(), this.removeName(this.name, map));
}
if (this.suffix != null)
{
s = s + this.suffix;
}
for (IProperty<?> iproperty : this.ignored)
{
map.remove(iproperty);
}
return new ModelResourceLocation(s, this.getPropertyString(map));
}
private <T extends Comparable<T>> String removeName(IProperty<T> property, Map < IProperty<?>, Comparable<? >> values)
{
return property.getName((T)values.remove(this.name));
}
@SideOnly(Side.CLIENT)
public static class Builder
{
private IProperty<?> name;
private String suffix;
private final List < IProperty<? >> ignored = Lists. < IProperty<? >> newArrayList();
public StateMap.Builder withName(IProperty<?> builderPropertyIn)
{
this.name = builderPropertyIn;
return this;
}
public StateMap.Builder withSuffix(String builderSuffixIn)
{
this.suffix = builderSuffixIn;
return this;
}
/**
* Ignore the listed {@code IProperty}s when building the variant string for the final {@code
* ModelResourceLocation}. It is valid to pass a {@code Block} that does not have one of these {@code
* IProperty}s to the built {@code StateMap}.
* @return {@code this}, for convenience in chaining
*
* @param ignores the {@code IProperty}s to ignore when building a variant string
*/
public StateMap.Builder ignore(IProperty<?>... ignores)
{
Collections.addAll(this.ignored, ignores);
return this;
}
/**
* Build a new {@code StateMap} with the settings contained in this {@code StateMap.Builder}. The {@code
* StateMap} will work with any {@code Block} that has the required {@code IProperty}s.
* @return a new {@code StateMap} with the settings contained in this {@code StateMap.Builder}
* @see #ignore(IProperty...)
* @see #withName(IProperty)
* @see #withSuffix(String)
*/
public StateMap build()
{
return new StateMap(this.name, this.suffix, this.ignored);
}
}
}

View File

@@ -0,0 +1,63 @@
package net.minecraft.client.renderer.block.statemap;
import com.google.common.collect.Maps;
import com.google.common.collect.UnmodifiableIterator;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class StateMapperBase implements IStateMapper
{
protected Map<IBlockState, ModelResourceLocation> mapStateModelLocations = Maps.<IBlockState, ModelResourceLocation>newLinkedHashMap();
public String getPropertyString(Map < IProperty<?>, Comparable<? >> values)
{
StringBuilder stringbuilder = new StringBuilder();
for (Entry < IProperty<?>, Comparable<? >> entry : values.entrySet())
{
if (stringbuilder.length() != 0)
{
stringbuilder.append(",");
}
IProperty<?> iproperty = (IProperty)entry.getKey();
stringbuilder.append(iproperty.getName());
stringbuilder.append("=");
stringbuilder.append(this.getPropertyName(iproperty, entry.getValue()));
}
if (stringbuilder.length() == 0)
{
stringbuilder.append("normal");
}
return stringbuilder.toString();
}
private <T extends Comparable<T>> String getPropertyName(IProperty<T> property, Comparable<?> value)
{
return property.getName((T)value);
}
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block blockIn)
{
UnmodifiableIterator unmodifiableiterator = blockIn.getBlockState().getValidStates().iterator();
while (unmodifiableiterator.hasNext())
{
IBlockState iblockstate = (IBlockState)unmodifiableiterator.next();
this.mapStateModelLocations.put(iblockstate, this.getModelResourceLocation(iblockstate));
}
return this.mapStateModelLocations;
}
protected abstract ModelResourceLocation getModelResourceLocation(IBlockState state);
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.client.renderer.block.statemap;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,159 @@
package net.minecraft.client.renderer.chunk;
import com.google.common.collect.Lists;
import com.google.common.primitives.Doubles;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import net.minecraft.client.renderer.RegionRenderCacheBuilder;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ChunkCompileTaskGenerator implements Comparable<ChunkCompileTaskGenerator>
{
private final RenderChunk renderChunk;
private final ReentrantLock lock = new ReentrantLock();
private final List<Runnable> listFinishRunnables = Lists.<Runnable>newArrayList();
private final ChunkCompileTaskGenerator.Type type;
private final double distanceSq;
private RegionRenderCacheBuilder regionRenderCacheBuilder;
private CompiledChunk compiledChunk;
private ChunkCompileTaskGenerator.Status status = ChunkCompileTaskGenerator.Status.PENDING;
private boolean finished;
public ChunkCompileTaskGenerator(RenderChunk renderChunkIn, ChunkCompileTaskGenerator.Type typeIn, double distanceSqIn)
{
this.renderChunk = renderChunkIn;
this.type = typeIn;
this.distanceSq = distanceSqIn;
}
public ChunkCompileTaskGenerator.Status getStatus()
{
return this.status;
}
public RenderChunk getRenderChunk()
{
return this.renderChunk;
}
public CompiledChunk getCompiledChunk()
{
return this.compiledChunk;
}
public void setCompiledChunk(CompiledChunk compiledChunkIn)
{
this.compiledChunk = compiledChunkIn;
}
public RegionRenderCacheBuilder getRegionRenderCacheBuilder()
{
return this.regionRenderCacheBuilder;
}
public void setRegionRenderCacheBuilder(RegionRenderCacheBuilder regionRenderCacheBuilderIn)
{
this.regionRenderCacheBuilder = regionRenderCacheBuilderIn;
}
public void setStatus(ChunkCompileTaskGenerator.Status statusIn)
{
this.lock.lock();
try
{
this.status = statusIn;
}
finally
{
this.lock.unlock();
}
}
public void finish()
{
this.lock.lock();
try
{
if (this.type == ChunkCompileTaskGenerator.Type.REBUILD_CHUNK && this.status != ChunkCompileTaskGenerator.Status.DONE)
{
this.renderChunk.setNeedsUpdate(false);
}
this.finished = true;
this.status = ChunkCompileTaskGenerator.Status.DONE;
for (Runnable runnable : this.listFinishRunnables)
{
runnable.run();
}
}
finally
{
this.lock.unlock();
}
}
public void addFinishRunnable(Runnable runnable)
{
this.lock.lock();
try
{
this.listFinishRunnables.add(runnable);
if (this.finished)
{
runnable.run();
}
}
finally
{
this.lock.unlock();
}
}
public ReentrantLock getLock()
{
return this.lock;
}
public ChunkCompileTaskGenerator.Type getType()
{
return this.type;
}
public boolean isFinished()
{
return this.finished;
}
public int compareTo(ChunkCompileTaskGenerator p_compareTo_1_)
{
return Doubles.compare(this.distanceSq, p_compareTo_1_.distanceSq);
}
public double getDistanceSq()
{
return this.distanceSq;
}
@SideOnly(Side.CLIENT)
public static enum Status
{
PENDING,
COMPILING,
UPLOADING,
DONE;
}
@SideOnly(Side.CLIENT)
public static enum Type
{
REBUILD_CHUNK,
RESORT_TRANSPARENCY;
}
}

View File

@@ -0,0 +1,373 @@
package net.minecraft.client.renderer.chunk;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.google.common.primitives.Doubles;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListenableFutureTask;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadFactory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RegionRenderCacheBuilder;
import net.minecraft.client.renderer.VertexBufferUploader;
import net.minecraft.client.renderer.WorldVertexBufferUploader;
import net.minecraft.client.renderer.vertex.VertexBuffer;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class ChunkRenderDispatcher
{
private static final Logger LOGGER = LogManager.getLogger();
private static final ThreadFactory THREAD_FACTORY = (new ThreadFactoryBuilder()).setNameFormat("Chunk Batcher %d").setDaemon(true).build();
private final int countRenderBuilders;
private final List<Thread> listWorkerThreads = Lists.<Thread>newArrayList();
private final List<ChunkRenderWorker> listThreadedWorkers = Lists.<ChunkRenderWorker>newArrayList();
private final PriorityBlockingQueue<ChunkCompileTaskGenerator> queueChunkUpdates = Queues.<ChunkCompileTaskGenerator>newPriorityBlockingQueue();
private final BlockingQueue<RegionRenderCacheBuilder> queueFreeRenderBuilders;
private final WorldVertexBufferUploader worldVertexUploader = new WorldVertexBufferUploader();
private final VertexBufferUploader vertexUploader = new VertexBufferUploader();
private final Queue<ChunkRenderDispatcher.PendingUpload> queueChunkUploads = Queues.<ChunkRenderDispatcher.PendingUpload>newPriorityQueue();
private final ChunkRenderWorker renderWorker;
public ChunkRenderDispatcher()
{
this(-1);
}
public ChunkRenderDispatcher(int countRenderBuilders)
{
int i = Math.max(1, (int)((double)Runtime.getRuntime().maxMemory() * 0.3D) / 10485760);
int j = Math.max(1, MathHelper.clamp(Runtime.getRuntime().availableProcessors(), 1, i / 5));
if(countRenderBuilders < 0) countRenderBuilders = MathHelper.clamp(j * 10, 1, i);
this.countRenderBuilders = countRenderBuilders;
if (j > 1)
{
for (int k = 0; k < j; ++k)
{
ChunkRenderWorker chunkrenderworker = new ChunkRenderWorker(this);
Thread thread = THREAD_FACTORY.newThread(chunkrenderworker);
thread.start();
this.listThreadedWorkers.add(chunkrenderworker);
this.listWorkerThreads.add(thread);
}
}
this.queueFreeRenderBuilders = Queues.<RegionRenderCacheBuilder>newArrayBlockingQueue(this.countRenderBuilders);
for (int l = 0; l < this.countRenderBuilders; ++l)
{
this.queueFreeRenderBuilders.add(new RegionRenderCacheBuilder());
}
this.renderWorker = new ChunkRenderWorker(this, new RegionRenderCacheBuilder());
}
public String getDebugInfo()
{
return this.listWorkerThreads.isEmpty() ? String.format("pC: %03d, single-threaded", this.queueChunkUpdates.size()) : String.format("pC: %03d, pU: %1d, aB: %1d", this.queueChunkUpdates.size(), this.queueChunkUploads.size(), this.queueFreeRenderBuilders.size());
}
public boolean runChunkUploads(long finishTimeNano)
{
boolean flag = false;
while (true)
{
boolean flag1 = false;
if (this.listWorkerThreads.isEmpty())
{
ChunkCompileTaskGenerator chunkcompiletaskgenerator = this.queueChunkUpdates.poll();
if (chunkcompiletaskgenerator != null)
{
try
{
this.renderWorker.processTask(chunkcompiletaskgenerator);
flag1 = true;
}
catch (InterruptedException var8)
{
LOGGER.warn("Skipped task due to interrupt");
}
}
}
synchronized (this.queueChunkUploads)
{
if (!this.queueChunkUploads.isEmpty())
{
(this.queueChunkUploads.poll()).uploadTask.run();
flag1 = true;
flag = true;
}
}
if (finishTimeNano == 0L || !flag1 || finishTimeNano < System.nanoTime())
{
break;
}
}
return flag;
}
public boolean updateChunkLater(RenderChunk chunkRenderer)
{
chunkRenderer.getLockCompileTask().lock();
boolean flag1;
try
{
final ChunkCompileTaskGenerator chunkcompiletaskgenerator = chunkRenderer.makeCompileTaskChunk();
chunkcompiletaskgenerator.addFinishRunnable(new Runnable()
{
public void run()
{
ChunkRenderDispatcher.this.queueChunkUpdates.remove(chunkcompiletaskgenerator);
}
});
boolean flag = this.queueChunkUpdates.offer(chunkcompiletaskgenerator);
if (!flag)
{
chunkcompiletaskgenerator.finish();
}
flag1 = flag;
}
finally
{
chunkRenderer.getLockCompileTask().unlock();
}
return flag1;
}
public boolean updateChunkNow(RenderChunk chunkRenderer)
{
chunkRenderer.getLockCompileTask().lock();
boolean flag;
try
{
ChunkCompileTaskGenerator chunkcompiletaskgenerator = chunkRenderer.makeCompileTaskChunk();
try
{
this.renderWorker.processTask(chunkcompiletaskgenerator);
}
catch (InterruptedException var7)
{
;
}
flag = true;
}
finally
{
chunkRenderer.getLockCompileTask().unlock();
}
return flag;
}
public void stopChunkUpdates()
{
this.clearChunkUpdates();
List<RegionRenderCacheBuilder> list = Lists.<RegionRenderCacheBuilder>newArrayList();
while (list.size() != this.countRenderBuilders)
{
this.runChunkUploads(Long.MAX_VALUE);
try
{
list.add(this.allocateRenderBuilder());
}
catch (InterruptedException var3)
{
;
}
}
this.queueFreeRenderBuilders.addAll(list);
}
public void freeRenderBuilder(RegionRenderCacheBuilder p_178512_1_)
{
this.queueFreeRenderBuilders.add(p_178512_1_);
}
public RegionRenderCacheBuilder allocateRenderBuilder() throws InterruptedException
{
return this.queueFreeRenderBuilders.take();
}
public ChunkCompileTaskGenerator getNextChunkUpdate() throws InterruptedException
{
return this.queueChunkUpdates.take();
}
public boolean updateTransparencyLater(RenderChunk chunkRenderer)
{
chunkRenderer.getLockCompileTask().lock();
boolean flag;
try
{
final ChunkCompileTaskGenerator chunkcompiletaskgenerator = chunkRenderer.makeCompileTaskTransparency();
if (chunkcompiletaskgenerator == null)
{
flag = true;
return flag;
}
chunkcompiletaskgenerator.addFinishRunnable(new Runnable()
{
public void run()
{
ChunkRenderDispatcher.this.queueChunkUpdates.remove(chunkcompiletaskgenerator);
}
});
flag = this.queueChunkUpdates.offer(chunkcompiletaskgenerator);
}
finally
{
chunkRenderer.getLockCompileTask().unlock();
}
return flag;
}
public ListenableFuture<Object> uploadChunk(final BlockRenderLayer p_188245_1_, final BufferBuilder p_188245_2_, final RenderChunk p_188245_3_, final CompiledChunk p_188245_4_, final double p_188245_5_)
{
if (Minecraft.getMinecraft().isCallingFromMinecraftThread())
{
if (OpenGlHelper.useVbo())
{
this.uploadVertexBuffer(p_188245_2_, p_188245_3_.getVertexBufferByLayer(p_188245_1_.ordinal()));
}
else
{
this.uploadDisplayList(p_188245_2_, ((ListedRenderChunk)p_188245_3_).getDisplayList(p_188245_1_, p_188245_4_), p_188245_3_);
}
p_188245_2_.setTranslation(0.0D, 0.0D, 0.0D);
return Futures.<Object>immediateFuture((Object)null);
}
else
{
ListenableFutureTask<Object> listenablefuturetask = ListenableFutureTask.<Object>create(new Runnable()
{
public void run()
{
ChunkRenderDispatcher.this.uploadChunk(p_188245_1_, p_188245_2_, p_188245_3_, p_188245_4_, p_188245_5_);
}
}, (Object)null);
synchronized (this.queueChunkUploads)
{
this.queueChunkUploads.add(new ChunkRenderDispatcher.PendingUpload(listenablefuturetask, p_188245_5_));
return listenablefuturetask;
}
}
}
private void uploadDisplayList(BufferBuilder bufferBuilderIn, int list, RenderChunk chunkRenderer)
{
GlStateManager.glNewList(list, 4864);
GlStateManager.pushMatrix();
chunkRenderer.multModelviewMatrix();
this.worldVertexUploader.draw(bufferBuilderIn);
GlStateManager.popMatrix();
GlStateManager.glEndList();
}
private void uploadVertexBuffer(BufferBuilder p_178506_1_, VertexBuffer vertexBufferIn)
{
this.vertexUploader.setVertexBuffer(vertexBufferIn);
this.vertexUploader.draw(p_178506_1_);
}
public void clearChunkUpdates()
{
while (!this.queueChunkUpdates.isEmpty())
{
ChunkCompileTaskGenerator chunkcompiletaskgenerator = this.queueChunkUpdates.poll();
if (chunkcompiletaskgenerator != null)
{
chunkcompiletaskgenerator.finish();
}
}
}
public boolean hasChunkUpdates()
{
return this.queueChunkUpdates.isEmpty() && this.queueChunkUploads.isEmpty();
}
public void stopWorkerThreads()
{
this.clearChunkUpdates();
for (ChunkRenderWorker chunkrenderworker : this.listThreadedWorkers)
{
chunkrenderworker.notifyToStop();
}
for (Thread thread : this.listWorkerThreads)
{
try
{
thread.interrupt();
thread.join();
}
catch (InterruptedException interruptedexception)
{
LOGGER.warn("Interrupted whilst waiting for worker to die", (Throwable)interruptedexception);
}
}
this.queueFreeRenderBuilders.clear();
}
public boolean hasNoFreeRenderBuilders()
{
return this.queueFreeRenderBuilders.isEmpty();
}
@SideOnly(Side.CLIENT)
class PendingUpload implements Comparable<ChunkRenderDispatcher.PendingUpload>
{
private final ListenableFutureTask<Object> uploadTask;
private final double distanceSq;
public PendingUpload(ListenableFutureTask<Object> uploadTaskIn, double distanceSqIn)
{
this.uploadTask = uploadTaskIn;
this.distanceSq = distanceSqIn;
}
public int compareTo(ChunkRenderDispatcher.PendingUpload p_compareTo_1_)
{
return Doubles.compare(this.distanceSq, p_compareTo_1_.distanceSq);
}
}
}

View File

@@ -0,0 +1,242 @@
package net.minecraft.client.renderer.chunk;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CancellationException;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RegionRenderCacheBuilder;
import net.minecraft.crash.CrashReport;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class ChunkRenderWorker implements Runnable
{
private static final Logger LOGGER = LogManager.getLogger();
private final ChunkRenderDispatcher chunkRenderDispatcher;
private final RegionRenderCacheBuilder regionRenderCacheBuilder;
private boolean shouldRun;
public ChunkRenderWorker(ChunkRenderDispatcher chunkRenderDispatcherIn)
{
this(chunkRenderDispatcherIn, (RegionRenderCacheBuilder)null);
}
public ChunkRenderWorker(ChunkRenderDispatcher chunkRenderDispatcherIn, @Nullable RegionRenderCacheBuilder regionRenderCacheBuilderIn)
{
this.shouldRun = true;
this.chunkRenderDispatcher = chunkRenderDispatcherIn;
this.regionRenderCacheBuilder = regionRenderCacheBuilderIn;
}
public void run()
{
while (this.shouldRun)
{
try
{
this.processTask(this.chunkRenderDispatcher.getNextChunkUpdate());
}
catch (InterruptedException var3)
{
LOGGER.debug("Stopping chunk worker due to interrupt");
return;
}
catch (Throwable throwable)
{
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Batching chunks");
Minecraft.getMinecraft().crashed(Minecraft.getMinecraft().addGraphicsAndWorldToCrashReport(crashreport));
return;
}
}
}
protected void processTask(final ChunkCompileTaskGenerator generator) throws InterruptedException
{
generator.getLock().lock();
try
{
if (generator.getStatus() != ChunkCompileTaskGenerator.Status.PENDING)
{
if (!generator.isFinished())
{
LOGGER.warn("Chunk render task was {} when I expected it to be pending; ignoring task", (Object)generator.getStatus());
}
return;
}
BlockPos blockpos = new BlockPos(Minecraft.getMinecraft().player);
BlockPos blockpos1 = generator.getRenderChunk().getPosition();
int i = 16;
int j = 8;
int k = 24;
if (blockpos1.add(8, 8, 8).distanceSq(blockpos) > 576.0D)
{
World world = generator.getRenderChunk().getWorld();
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(blockpos1);
if (!this.isChunkExisting(blockpos$mutableblockpos.setPos(blockpos1).move(EnumFacing.WEST, 16), world) || !this.isChunkExisting(blockpos$mutableblockpos.setPos(blockpos1).move(EnumFacing.NORTH, 16), world) || !this.isChunkExisting(blockpos$mutableblockpos.setPos(blockpos1).move(EnumFacing.EAST, 16), world) || !this.isChunkExisting(blockpos$mutableblockpos.setPos(blockpos1).move(EnumFacing.SOUTH, 16), world))
{
return;
}
}
generator.setStatus(ChunkCompileTaskGenerator.Status.COMPILING);
}
finally
{
generator.getLock().unlock();
}
Entity entity = Minecraft.getMinecraft().getRenderViewEntity();
if (entity == null)
{
generator.finish();
}
else
{
generator.setRegionRenderCacheBuilder(this.getRegionRenderCacheBuilder());
float f = (float)entity.posX;
float f1 = (float)entity.posY + entity.getEyeHeight();
float f2 = (float)entity.posZ;
ChunkCompileTaskGenerator.Type chunkcompiletaskgenerator$type = generator.getType();
if (chunkcompiletaskgenerator$type == ChunkCompileTaskGenerator.Type.REBUILD_CHUNK)
{
generator.getRenderChunk().rebuildChunk(f, f1, f2, generator);
}
else if (chunkcompiletaskgenerator$type == ChunkCompileTaskGenerator.Type.RESORT_TRANSPARENCY)
{
generator.getRenderChunk().resortTransparency(f, f1, f2, generator);
}
generator.getLock().lock();
try
{
if (generator.getStatus() != ChunkCompileTaskGenerator.Status.COMPILING)
{
if (!generator.isFinished())
{
LOGGER.warn("Chunk render task was {} when I expected it to be compiling; aborting task", (Object)generator.getStatus());
}
this.freeRenderBuilder(generator);
return;
}
generator.setStatus(ChunkCompileTaskGenerator.Status.UPLOADING);
}
finally
{
generator.getLock().unlock();
}
final CompiledChunk compiledchunk = generator.getCompiledChunk();
ArrayList arraylist = Lists.newArrayList();
if (chunkcompiletaskgenerator$type == ChunkCompileTaskGenerator.Type.REBUILD_CHUNK)
{
for (BlockRenderLayer blockrenderlayer : BlockRenderLayer.values())
{
if (compiledchunk.isLayerStarted(blockrenderlayer))
{
arraylist.add(this.chunkRenderDispatcher.uploadChunk(blockrenderlayer, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(blockrenderlayer), generator.getRenderChunk(), compiledchunk, generator.getDistanceSq()));
}
}
}
else if (chunkcompiletaskgenerator$type == ChunkCompileTaskGenerator.Type.RESORT_TRANSPARENCY)
{
arraylist.add(this.chunkRenderDispatcher.uploadChunk(BlockRenderLayer.TRANSLUCENT, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(BlockRenderLayer.TRANSLUCENT), generator.getRenderChunk(), compiledchunk, generator.getDistanceSq()));
}
final ListenableFuture<List<Object>> listenablefuture = Futures.allAsList(arraylist);
generator.addFinishRunnable(new Runnable()
{
public void run()
{
listenablefuture.cancel(false);
}
});
Futures.addCallback(listenablefuture, new FutureCallback<List<Object>>()
{
public void onSuccess(@Nullable List<Object> p_onSuccess_1_)
{
ChunkRenderWorker.this.freeRenderBuilder(generator);
generator.getLock().lock();
label49:
{
try
{
if (generator.getStatus() == ChunkCompileTaskGenerator.Status.UPLOADING)
{
generator.setStatus(ChunkCompileTaskGenerator.Status.DONE);
break label49;
}
if (!generator.isFinished())
{
ChunkRenderWorker.LOGGER.warn("Chunk render task was {} when I expected it to be uploading; aborting task", (Object)generator.getStatus());
}
}
finally
{
generator.getLock().unlock();
}
return;
}
generator.getRenderChunk().setCompiledChunk(compiledchunk);
}
public void onFailure(Throwable p_onFailure_1_)
{
ChunkRenderWorker.this.freeRenderBuilder(generator);
if (!(p_onFailure_1_ instanceof CancellationException) && !(p_onFailure_1_ instanceof InterruptedException))
{
Minecraft.getMinecraft().crashed(CrashReport.makeCrashReport(p_onFailure_1_, "Rendering chunk"));
}
}
});
}
}
private boolean isChunkExisting(BlockPos pos, World worldIn)
{
return !worldIn.getChunkFromChunkCoords(pos.getX() >> 4, pos.getZ() >> 4).isEmpty();
}
private RegionRenderCacheBuilder getRegionRenderCacheBuilder() throws InterruptedException
{
return this.regionRenderCacheBuilder != null ? this.regionRenderCacheBuilder : this.chunkRenderDispatcher.allocateRenderBuilder();
}
private void freeRenderBuilder(ChunkCompileTaskGenerator taskGenerator)
{
if (this.regionRenderCacheBuilder == null)
{
this.chunkRenderDispatcher.freeRenderBuilder(taskGenerator.getRegionRenderCacheBuilder());
}
}
public void notifyToStop()
{
this.shouldRun = false;
}
}

View File

@@ -0,0 +1,92 @@
package net.minecraft.client.renderer.chunk;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class CompiledChunk
{
public static final CompiledChunk DUMMY = new CompiledChunk()
{
protected void setLayerUsed(BlockRenderLayer layer)
{
throw new UnsupportedOperationException();
}
public void setLayerStarted(BlockRenderLayer layer)
{
throw new UnsupportedOperationException();
}
public boolean isVisible(EnumFacing facing, EnumFacing facing2)
{
return false;
}
};
private final boolean[] layersUsed = new boolean[BlockRenderLayer.values().length];
private final boolean[] layersStarted = new boolean[BlockRenderLayer.values().length];
private boolean empty = true;
private final List<TileEntity> tileEntities = Lists.<TileEntity>newArrayList();
private SetVisibility setVisibility = new SetVisibility();
private BufferBuilder.State state;
public boolean isEmpty()
{
return this.empty;
}
protected void setLayerUsed(BlockRenderLayer layer)
{
this.empty = false;
this.layersUsed[layer.ordinal()] = true;
}
public boolean isLayerEmpty(BlockRenderLayer layer)
{
return !this.layersUsed[layer.ordinal()];
}
public void setLayerStarted(BlockRenderLayer layer)
{
this.layersStarted[layer.ordinal()] = true;
}
public boolean isLayerStarted(BlockRenderLayer layer)
{
return this.layersStarted[layer.ordinal()];
}
public List<TileEntity> getTileEntities()
{
return this.tileEntities;
}
public void addTileEntity(TileEntity tileEntityIn)
{
this.tileEntities.add(tileEntityIn);
}
public boolean isVisible(EnumFacing facing, EnumFacing facing2)
{
return this.setVisibility.isVisible(facing, facing2);
}
public void setVisibility(SetVisibility visibility)
{
this.setVisibility = visibility;
}
public BufferBuilder.State getState()
{
return this.state;
}
public void setState(BufferBuilder.State stateIn)
{
this.state = stateIn;
}
}

View File

@@ -0,0 +1,12 @@
package net.minecraft.client.renderer.chunk;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IRenderChunkFactory
{
RenderChunk create(World worldIn, RenderGlobal renderGlobalIn, int index);
}

View File

@@ -0,0 +1,15 @@
package net.minecraft.client.renderer.chunk;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ListChunkFactory implements IRenderChunkFactory
{
public RenderChunk create(World worldIn, RenderGlobal renderGlobalIn, int index)
{
return new ListedRenderChunk(worldIn, renderGlobalIn, index);
}
}

View File

@@ -0,0 +1,30 @@
package net.minecraft.client.renderer.chunk;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ListedRenderChunk extends RenderChunk
{
private final int baseDisplayList = GLAllocation.generateDisplayLists(BlockRenderLayer.values().length);
public ListedRenderChunk(World worldIn, RenderGlobal renderGlobalIn, int index)
{
super(worldIn, renderGlobalIn, index);
}
public int getDisplayList(BlockRenderLayer layer, CompiledChunk p_178600_2_)
{
return !p_178600_2_.isLayerEmpty(layer) ? this.baseDisplayList + layer.ordinal() : -1;
}
public void deleteGlResources()
{
super.deleteGlResources();
GLAllocation.deleteDisplayLists(this.baseDisplayList, BlockRenderLayer.values().length);
}
}

View File

@@ -0,0 +1,468 @@
package net.minecraft.client.renderer.chunk;
import com.google.common.collect.Sets;
import java.nio.FloatBuffer;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkCache;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderChunk
{
private World world;
private final RenderGlobal renderGlobal;
public static int renderChunksUpdated;
public CompiledChunk compiledChunk = CompiledChunk.DUMMY;
private final ReentrantLock lockCompileTask = new ReentrantLock();
private final ReentrantLock lockCompiledChunk = new ReentrantLock();
private ChunkCompileTaskGenerator compileTask;
private final Set<TileEntity> setTileEntities = Sets.<TileEntity>newHashSet();
private final int index;
private final FloatBuffer modelviewMatrix = GLAllocation.createDirectFloatBuffer(16);
private final VertexBuffer[] vertexBuffers = new VertexBuffer[BlockRenderLayer.values().length];
public AxisAlignedBB boundingBox;
private int frameIndex = -1;
private boolean needsUpdate = true;
private final BlockPos.MutableBlockPos position = new BlockPos.MutableBlockPos(-1, -1, -1);
private final BlockPos.MutableBlockPos[] mapEnumFacing = new BlockPos.MutableBlockPos[6];
private boolean needsImmediateUpdate;
private ChunkCache worldView;
public RenderChunk(World worldIn, RenderGlobal renderGlobalIn, int indexIn)
{
for (int i = 0; i < this.mapEnumFacing.length; ++i)
{
this.mapEnumFacing[i] = new BlockPos.MutableBlockPos();
}
this.world = worldIn;
this.renderGlobal = renderGlobalIn;
this.index = indexIn;
if (OpenGlHelper.useVbo())
{
for (int j = 0; j < BlockRenderLayer.values().length; ++j)
{
this.vertexBuffers[j] = new VertexBuffer(DefaultVertexFormats.BLOCK);
}
}
}
public boolean setFrameIndex(int frameIndexIn)
{
if (this.frameIndex == frameIndexIn)
{
return false;
}
else
{
this.frameIndex = frameIndexIn;
return true;
}
}
public VertexBuffer getVertexBufferByLayer(int layer)
{
return this.vertexBuffers[layer];
}
/**
* Sets the RenderChunk base position
*/
public void setPosition(int x, int y, int z)
{
if (x != this.position.getX() || y != this.position.getY() || z != this.position.getZ())
{
this.stopCompileTask();
this.position.setPos(x, y, z);
this.boundingBox = new AxisAlignedBB((double)x, (double)y, (double)z, (double)(x + 16), (double)(y + 16), (double)(z + 16));
for (EnumFacing enumfacing : EnumFacing.values())
{
this.mapEnumFacing[enumfacing.ordinal()].setPos(this.position).move(enumfacing, 16);
}
this.initModelviewMatrix();
}
}
public void resortTransparency(float x, float y, float z, ChunkCompileTaskGenerator generator)
{
CompiledChunk compiledchunk = generator.getCompiledChunk();
if (compiledchunk.getState() != null && !compiledchunk.isLayerEmpty(BlockRenderLayer.TRANSLUCENT))
{
this.preRenderBlocks(generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(BlockRenderLayer.TRANSLUCENT), this.position);
generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(BlockRenderLayer.TRANSLUCENT).setVertexState(compiledchunk.getState());
this.postRenderBlocks(BlockRenderLayer.TRANSLUCENT, x, y, z, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(BlockRenderLayer.TRANSLUCENT), compiledchunk);
}
}
public void rebuildChunk(float x, float y, float z, ChunkCompileTaskGenerator generator)
{
CompiledChunk compiledchunk = new CompiledChunk();
int i = 1;
BlockPos blockpos = this.position;
BlockPos blockpos1 = blockpos.add(15, 15, 15);
generator.getLock().lock();
try
{
if (generator.getStatus() != ChunkCompileTaskGenerator.Status.COMPILING)
{
return;
}
generator.setCompiledChunk(compiledchunk);
}
finally
{
generator.getLock().unlock();
}
VisGraph lvt_9_1_ = new VisGraph();
HashSet lvt_10_1_ = Sets.newHashSet();
if (!this.worldView.isEmpty())
{
++renderChunksUpdated;
boolean[] aboolean = new boolean[BlockRenderLayer.values().length];
BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos1))
{
IBlockState iblockstate = this.worldView.getBlockState(blockpos$mutableblockpos);
Block block = iblockstate.getBlock();
if (iblockstate.isOpaqueCube())
{
lvt_9_1_.setOpaqueCube(blockpos$mutableblockpos);
}
if (block.hasTileEntity(iblockstate))
{
TileEntity tileentity = this.worldView.getTileEntity(blockpos$mutableblockpos, Chunk.EnumCreateEntityType.CHECK);
if (tileentity != null)
{
TileEntitySpecialRenderer<TileEntity> tileentityspecialrenderer = TileEntityRendererDispatcher.instance.<TileEntity>getRenderer(tileentity);
if (tileentityspecialrenderer != null)
{
if (tileentityspecialrenderer.isGlobalRenderer(tileentity))
{
lvt_10_1_.add(tileentity);
}
else compiledchunk.addTileEntity(tileentity); // FORGE: Fix MC-112730
}
}
}
for(BlockRenderLayer blockrenderlayer1 : BlockRenderLayer.values()) {
if(!block.canRenderInLayer(iblockstate, blockrenderlayer1)) continue;
net.minecraftforge.client.ForgeHooksClient.setRenderLayer(blockrenderlayer1);
int j = blockrenderlayer1.ordinal();
if (block.getDefaultState().getRenderType() != EnumBlockRenderType.INVISIBLE)
{
BufferBuilder bufferbuilder = generator.getRegionRenderCacheBuilder().getWorldRendererByLayerId(j);
if (!compiledchunk.isLayerStarted(blockrenderlayer1))
{
compiledchunk.setLayerStarted(blockrenderlayer1);
this.preRenderBlocks(bufferbuilder, blockpos);
}
aboolean[j] |= blockrendererdispatcher.renderBlock(iblockstate, blockpos$mutableblockpos, this.worldView, bufferbuilder);
}
}
net.minecraftforge.client.ForgeHooksClient.setRenderLayer(null);
}
for (BlockRenderLayer blockrenderlayer : BlockRenderLayer.values())
{
if (aboolean[blockrenderlayer.ordinal()])
{
compiledchunk.setLayerUsed(blockrenderlayer);
}
if (compiledchunk.isLayerStarted(blockrenderlayer))
{
this.postRenderBlocks(blockrenderlayer, x, y, z, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(blockrenderlayer), compiledchunk);
}
}
}
compiledchunk.setVisibility(lvt_9_1_.computeVisibility());
this.lockCompileTask.lock();
try
{
Set<TileEntity> set = Sets.newHashSet(lvt_10_1_);
Set<TileEntity> set1 = Sets.newHashSet(this.setTileEntities);
set.removeAll(this.setTileEntities);
set1.removeAll(lvt_10_1_);
this.setTileEntities.clear();
this.setTileEntities.addAll(lvt_10_1_);
this.renderGlobal.updateTileEntities(set1, set);
}
finally
{
this.lockCompileTask.unlock();
}
}
protected void finishCompileTask()
{
this.lockCompileTask.lock();
try
{
if (this.compileTask != null && this.compileTask.getStatus() != ChunkCompileTaskGenerator.Status.DONE)
{
this.compileTask.finish();
this.compileTask = null;
}
}
finally
{
this.lockCompileTask.unlock();
}
}
public ReentrantLock getLockCompileTask()
{
return this.lockCompileTask;
}
public ChunkCompileTaskGenerator makeCompileTaskChunk()
{
this.lockCompileTask.lock();
ChunkCompileTaskGenerator chunkcompiletaskgenerator;
try
{
this.finishCompileTask();
this.compileTask = new ChunkCompileTaskGenerator(this, ChunkCompileTaskGenerator.Type.REBUILD_CHUNK, this.getDistanceSq());
this.rebuildWorldView();
chunkcompiletaskgenerator = this.compileTask;
}
finally
{
this.lockCompileTask.unlock();
}
return chunkcompiletaskgenerator;
}
private void rebuildWorldView()
{
int i = 1;
ChunkCache cache = createRegionRenderCache(this.world, this.position.add(-1, -1, -1), this.position.add(16, 16, 16), 1);
net.minecraftforge.client.MinecraftForgeClient.onRebuildChunk(this.world, this.position, cache);
this.worldView = cache;
}
@Nullable
public ChunkCompileTaskGenerator makeCompileTaskTransparency()
{
this.lockCompileTask.lock();
ChunkCompileTaskGenerator chunkcompiletaskgenerator;
try
{
if (this.compileTask == null || this.compileTask.getStatus() != ChunkCompileTaskGenerator.Status.PENDING)
{
if (this.compileTask != null && this.compileTask.getStatus() != ChunkCompileTaskGenerator.Status.DONE)
{
this.compileTask.finish();
this.compileTask = null;
}
this.compileTask = new ChunkCompileTaskGenerator(this, ChunkCompileTaskGenerator.Type.RESORT_TRANSPARENCY, this.getDistanceSq());
this.compileTask.setCompiledChunk(this.compiledChunk);
chunkcompiletaskgenerator = this.compileTask;
return chunkcompiletaskgenerator;
}
chunkcompiletaskgenerator = null;
}
finally
{
this.lockCompileTask.unlock();
}
return chunkcompiletaskgenerator;
}
protected double getDistanceSq()
{
EntityPlayerSP entityplayersp = Minecraft.getMinecraft().player;
double d0 = this.boundingBox.minX + 8.0D - entityplayersp.posX;
double d1 = this.boundingBox.minY + 8.0D - entityplayersp.posY;
double d2 = this.boundingBox.minZ + 8.0D - entityplayersp.posZ;
return d0 * d0 + d1 * d1 + d2 * d2;
}
private void preRenderBlocks(BufferBuilder bufferBuilderIn, BlockPos pos)
{
bufferBuilderIn.begin(7, DefaultVertexFormats.BLOCK);
bufferBuilderIn.setTranslation((double)(-pos.getX()), (double)(-pos.getY()), (double)(-pos.getZ()));
}
private void postRenderBlocks(BlockRenderLayer layer, float x, float y, float z, BufferBuilder bufferBuilderIn, CompiledChunk compiledChunkIn)
{
if (layer == BlockRenderLayer.TRANSLUCENT && !compiledChunkIn.isLayerEmpty(layer))
{
bufferBuilderIn.sortVertexData(x, y, z);
compiledChunkIn.setState(bufferBuilderIn.getVertexState());
}
bufferBuilderIn.finishDrawing();
}
private void initModelviewMatrix()
{
GlStateManager.pushMatrix();
GlStateManager.loadIdentity();
float f = 1.000001F;
GlStateManager.translate(-8.0F, -8.0F, -8.0F);
GlStateManager.scale(1.000001F, 1.000001F, 1.000001F);
GlStateManager.translate(8.0F, 8.0F, 8.0F);
GlStateManager.getFloat(2982, this.modelviewMatrix);
GlStateManager.popMatrix();
}
public void multModelviewMatrix()
{
GlStateManager.multMatrix(this.modelviewMatrix);
}
public CompiledChunk getCompiledChunk()
{
return this.compiledChunk;
}
public void setCompiledChunk(CompiledChunk compiledChunkIn)
{
this.lockCompiledChunk.lock();
try
{
this.compiledChunk = compiledChunkIn;
}
finally
{
this.lockCompiledChunk.unlock();
}
}
public void stopCompileTask()
{
this.finishCompileTask();
this.compiledChunk = CompiledChunk.DUMMY;
}
public void deleteGlResources()
{
this.stopCompileTask();
this.world = null;
for (int i = 0; i < BlockRenderLayer.values().length; ++i)
{
if (this.vertexBuffers[i] != null)
{
this.vertexBuffers[i].deleteGlBuffers();
}
}
}
public BlockPos getPosition()
{
return this.position;
}
public void setNeedsUpdate(boolean immediate)
{
if (this.needsUpdate)
{
immediate |= this.needsImmediateUpdate;
}
this.needsUpdate = true;
this.needsImmediateUpdate = immediate;
}
public void clearNeedsUpdate()
{
this.needsUpdate = false;
this.needsImmediateUpdate = false;
}
public boolean needsUpdate()
{
return this.needsUpdate;
}
public boolean needsImmediateUpdate()
{
return this.needsUpdate && this.needsImmediateUpdate;
}
/* ======================================== FORGE START =====================================*/
/**
* Creates a new RegionRenderCache instance.<br>
* Extending classes can change the behavior of the cache, allowing to visually change
* blocks (schematics etc).
*
* @see RegionRenderCache
* @param world The world to cache.
* @param from The starting position of the chunk minus one on each axis.
* @param to The ending position of the chunk plus one on each axis.
* @param subtract Padding used internally by the RegionRenderCache constructor to make
* the cache a 20x20x20 cube, for a total of 8000 states in the cache.
* @return new RegionRenderCache instance
*/
protected ChunkCache createRegionRenderCache(World world, BlockPos from, BlockPos to, int subtract)
{
return new ChunkCache(world, from, to, subtract);
}
/* ========================================= FORGE END ======================================*/
public BlockPos getBlockPosOffset16(EnumFacing facing)
{
return this.mapEnumFacing[facing.ordinal()];
}
public World getWorld()
{
return this.world;
}
}

View File

@@ -0,0 +1,81 @@
package net.minecraft.client.renderer.chunk;
import java.util.BitSet;
import java.util.Set;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class SetVisibility
{
private static final int COUNT_FACES = EnumFacing.values().length;
private final BitSet bitSet;
public SetVisibility()
{
this.bitSet = new BitSet(COUNT_FACES * COUNT_FACES);
}
public void setManyVisible(Set<EnumFacing> facing)
{
for (EnumFacing enumfacing : facing)
{
for (EnumFacing enumfacing1 : facing)
{
this.setVisible(enumfacing, enumfacing1, true);
}
}
}
public void setVisible(EnumFacing facing, EnumFacing facing2, boolean p_178619_3_)
{
this.bitSet.set(facing.ordinal() + facing2.ordinal() * COUNT_FACES, p_178619_3_);
this.bitSet.set(facing2.ordinal() + facing.ordinal() * COUNT_FACES, p_178619_3_);
}
public void setAllVisible(boolean visible)
{
this.bitSet.set(0, this.bitSet.size(), visible);
}
public boolean isVisible(EnumFacing facing, EnumFacing facing2)
{
return this.bitSet.get(facing.ordinal() + facing2.ordinal() * COUNT_FACES);
}
public String toString()
{
StringBuilder stringbuilder = new StringBuilder();
stringbuilder.append(' ');
for (EnumFacing enumfacing : EnumFacing.values())
{
stringbuilder.append(' ').append(enumfacing.toString().toUpperCase().charAt(0));
}
stringbuilder.append('\n');
for (EnumFacing enumfacing2 : EnumFacing.values())
{
stringbuilder.append(enumfacing2.toString().toUpperCase().charAt(0));
for (EnumFacing enumfacing1 : EnumFacing.values())
{
if (enumfacing2 == enumfacing1)
{
stringbuilder.append(" ");
}
else
{
boolean flag = this.isVisible(enumfacing2, enumfacing1);
stringbuilder.append(' ').append((char)(flag ? 'Y' : 'n'));
}
}
stringbuilder.append('\n');
}
return stringbuilder.toString();
}
}

View File

@@ -0,0 +1,15 @@
package net.minecraft.client.renderer.chunk;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class VboChunkFactory implements IRenderChunkFactory
{
public RenderChunk create(World worldIn, RenderGlobal renderGlobalIn, int index)
{
return new RenderChunk(worldIn, renderGlobalIn, index);
}
}

View File

@@ -0,0 +1,211 @@
package net.minecraft.client.renderer.chunk;
import com.google.common.collect.Queues;
import java.util.BitSet;
import java.util.EnumSet;
import java.util.Queue;
import java.util.Set;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IntegerCache;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class VisGraph
{
private static final int DX = (int)Math.pow(16.0D, 0.0D);
private static final int DZ = (int)Math.pow(16.0D, 1.0D);
private static final int DY = (int)Math.pow(16.0D, 2.0D);
private final BitSet bitSet = new BitSet(4096);
private static final int[] INDEX_OF_EDGES = new int[1352];
private int empty = 4096;
public void setOpaqueCube(BlockPos pos)
{
this.bitSet.set(getIndex(pos), true);
--this.empty;
}
private static int getIndex(BlockPos pos)
{
return getIndex(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
}
private static int getIndex(int x, int y, int z)
{
return x << 0 | y << 8 | z << 4;
}
public SetVisibility computeVisibility()
{
SetVisibility setvisibility = new SetVisibility();
if (4096 - this.empty < 256)
{
setvisibility.setAllVisible(true);
}
else if (this.empty == 0)
{
setvisibility.setAllVisible(false);
}
else
{
for (int i : INDEX_OF_EDGES)
{
if (!this.bitSet.get(i))
{
setvisibility.setManyVisible(this.floodFill(i));
}
}
}
return setvisibility;
}
public Set<EnumFacing> getVisibleFacings(BlockPos pos)
{
return this.floodFill(getIndex(pos));
}
private Set<EnumFacing> floodFill(int pos)
{
Set<EnumFacing> set = EnumSet.<EnumFacing>noneOf(EnumFacing.class);
Queue<Integer> queue = Queues.<Integer>newArrayDeque();
queue.add(IntegerCache.getInteger(pos));
this.bitSet.set(pos, true);
while (!queue.isEmpty())
{
int i = ((Integer)queue.poll()).intValue();
this.addEdges(i, set);
for (EnumFacing enumfacing : EnumFacing.values())
{
int j = this.getNeighborIndexAtFace(i, enumfacing);
if (j >= 0 && !this.bitSet.get(j))
{
this.bitSet.set(j, true);
queue.add(IntegerCache.getInteger(j));
}
}
}
return set;
}
private void addEdges(int pos, Set<EnumFacing> p_178610_2_)
{
int i = pos >> 0 & 15;
if (i == 0)
{
p_178610_2_.add(EnumFacing.WEST);
}
else if (i == 15)
{
p_178610_2_.add(EnumFacing.EAST);
}
int j = pos >> 8 & 15;
if (j == 0)
{
p_178610_2_.add(EnumFacing.DOWN);
}
else if (j == 15)
{
p_178610_2_.add(EnumFacing.UP);
}
int k = pos >> 4 & 15;
if (k == 0)
{
p_178610_2_.add(EnumFacing.NORTH);
}
else if (k == 15)
{
p_178610_2_.add(EnumFacing.SOUTH);
}
}
private int getNeighborIndexAtFace(int pos, EnumFacing facing)
{
switch (facing)
{
case DOWN:
if ((pos >> 8 & 15) == 0)
{
return -1;
}
return pos - DY;
case UP:
if ((pos >> 8 & 15) == 15)
{
return -1;
}
return pos + DY;
case NORTH:
if ((pos >> 4 & 15) == 0)
{
return -1;
}
return pos - DZ;
case SOUTH:
if ((pos >> 4 & 15) == 15)
{
return -1;
}
return pos + DZ;
case WEST:
if ((pos >> 0 & 15) == 0)
{
return -1;
}
return pos - DX;
case EAST:
if ((pos >> 0 & 15) == 15)
{
return -1;
}
return pos + DX;
default:
return -1;
}
}
static
{
int i = 0;
int j = 15;
int k = 0;
for (int l = 0; l < 16; ++l)
{
for (int i1 = 0; i1 < 16; ++i1)
{
for (int j1 = 0; j1 < 16; ++j1)
{
if (l == 0 || l == 15 || i1 == 0 || i1 == 15 || j1 == 0 || j1 == 15)
{
INDEX_OF_EDGES[k++] = getIndex(l, i1, j1);
}
}
}
}
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.client.renderer.chunk;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,197 @@
package net.minecraft.client.renderer.color;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.BlockRedstoneWire;
import net.minecraft.block.BlockStem;
import net.minecraft.block.BlockTallGrass;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFlowerPot;
import net.minecraft.util.ObjectIntIdentityMap;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ColorizerFoliage;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeColorHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BlockColors
{
// FORGE: Use RegistryDelegates as non-Vanilla block ids are not constant
private final java.util.Map<net.minecraftforge.registries.IRegistryDelegate<Block>, IBlockColor> blockColorMap = com.google.common.collect.Maps.newHashMap();
public static BlockColors init()
{
final BlockColors blockcolors = new BlockColors();
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(BlockDoublePlant.VARIANT);
return worldIn != null && pos != null && (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS || blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN) ? BiomeColorHelper.getGrassColorAtPos(worldIn, state.getValue(BlockDoublePlant.HALF) == BlockDoublePlant.EnumBlockHalf.UPPER ? pos.down() : pos) : -1;
}
}, Blocks.DOUBLE_PLANT);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
if (worldIn != null && pos != null)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityFlowerPot)
{
Item item = ((TileEntityFlowerPot)tileentity).getFlowerPotItem();
IBlockState iblockstate = Block.getBlockFromItem(item).getDefaultState();
return blockcolors.colorMultiplier(iblockstate, worldIn, pos, tintIndex);
}
else
{
return -1;
}
}
else
{
return -1;
}
}
}, Blocks.FLOWER_POT);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
return worldIn != null && pos != null ? BiomeColorHelper.getGrassColorAtPos(worldIn, pos) : ColorizerGrass.getGrassColor(0.5D, 1.0D);
}
}, Blocks.GRASS);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
BlockPlanks.EnumType blockplanks$enumtype = (BlockPlanks.EnumType)state.getValue(BlockOldLeaf.VARIANT);
if (blockplanks$enumtype == BlockPlanks.EnumType.SPRUCE)
{
return ColorizerFoliage.getFoliageColorPine();
}
else if (blockplanks$enumtype == BlockPlanks.EnumType.BIRCH)
{
return ColorizerFoliage.getFoliageColorBirch();
}
else
{
return worldIn != null && pos != null ? BiomeColorHelper.getFoliageColorAtPos(worldIn, pos) : ColorizerFoliage.getFoliageColorBasic();
}
}
}, Blocks.LEAVES);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
return worldIn != null && pos != null ? BiomeColorHelper.getFoliageColorAtPos(worldIn, pos) : ColorizerFoliage.getFoliageColorBasic();
}
}, Blocks.LEAVES2);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
return worldIn != null && pos != null ? BiomeColorHelper.getWaterColorAtPos(worldIn, pos) : -1;
}
}, Blocks.WATER, Blocks.FLOWING_WATER);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
return BlockRedstoneWire.colorMultiplier(((Integer)state.getValue(BlockRedstoneWire.POWER)).intValue());
}
}, Blocks.REDSTONE_WIRE);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
return worldIn != null && pos != null ? BiomeColorHelper.getGrassColorAtPos(worldIn, pos) : -1;
}
}, Blocks.REEDS);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
int i = ((Integer)state.getValue(BlockStem.AGE)).intValue();
int j = i * 32;
int k = 255 - i * 8;
int l = i * 4;
return j << 16 | k << 8 | l;
}
}, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
if (worldIn != null && pos != null)
{
return BiomeColorHelper.getGrassColorAtPos(worldIn, pos);
}
else
{
return state.getValue(BlockTallGrass.TYPE) == BlockTallGrass.EnumType.DEAD_BUSH ? 16777215 : ColorizerGrass.getGrassColor(0.5D, 1.0D);
}
}
}, Blocks.TALLGRASS);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
return worldIn != null && pos != null ? BiomeColorHelper.getFoliageColorAtPos(worldIn, pos) : ColorizerFoliage.getFoliageColorBasic();
}
}, Blocks.VINE);
blockcolors.registerBlockColorHandler(new IBlockColor()
{
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex)
{
return worldIn != null && pos != null ? 2129968 : 7455580;
}
}, Blocks.WATERLILY);
net.minecraftforge.client.ForgeHooksClient.onBlockColorsInit(blockcolors);
return blockcolors;
}
public int getColor(IBlockState state, World p_189991_2_, BlockPos p_189991_3_)
{
IBlockColor iblockcolor = this.blockColorMap.get(state.getBlock().delegate);
if (iblockcolor != null)
{
return iblockcolor.colorMultiplier(state, (IBlockAccess)null, (BlockPos)null, 0);
}
else
{
MapColor mapcolor = state.getMapColor(p_189991_2_, p_189991_3_);
return mapcolor != null ? mapcolor.colorValue : -1;
}
}
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess blockAccess, @Nullable BlockPos pos, int renderPass)
{
IBlockColor iblockcolor = this.blockColorMap.get(state.getBlock().delegate);
return iblockcolor == null ? -1 : iblockcolor.colorMultiplier(state, blockAccess, pos, renderPass);
}
public void registerBlockColorHandler(IBlockColor blockColor, Block... blocksIn)
{
for (Block block : blocksIn)
{
if (block == null) throw new IllegalArgumentException("Block registered to block color handler cannot be null!");
if (block.getRegistryName() == null) throw new IllegalArgumentException("Block must be registered before assigning color handler.");
this.blockColorMap.put(block.delegate, blockColor);
}
}
}

View File

@@ -0,0 +1,14 @@
package net.minecraft.client.renderer.color;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IBlockColor
{
int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex);
}

View File

@@ -0,0 +1,11 @@
package net.minecraft.client.renderer.color;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IItemColor
{
int colorMultiplier(ItemStack stack, int tintIndex);
}

View File

@@ -0,0 +1,170 @@
package net.minecraft.client.renderer.color;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityList;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemFireworkCharge;
import net.minecraft.item.ItemMap;
import net.minecraft.item.ItemMonsterPlacer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.ObjectIntIdentityMap;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ItemColors
{
// FORGE: Use RegistryDelegates as non-Vanilla item ids are not constant
private final java.util.Map<net.minecraftforge.registries.IRegistryDelegate<Item>, IItemColor> itemColorMap = com.google.common.collect.Maps.newHashMap();
public static ItemColors init(final BlockColors colors)
{
ItemColors itemcolors = new ItemColors();
itemcolors.registerItemColorHandler(new IItemColor()
{
public int colorMultiplier(ItemStack stack, int tintIndex)
{
return tintIndex > 0 ? -1 : ((ItemArmor)stack.getItem()).getColor(stack);
}
}, Items.LEATHER_HELMET, Items.LEATHER_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS);
itemcolors.registerItemColorHandler(new IItemColor()
{
public int colorMultiplier(ItemStack stack, int tintIndex)
{
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = BlockDoublePlant.EnumPlantType.byMetadata(stack.getMetadata());
return blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN ? -1 : ColorizerGrass.getGrassColor(0.5D, 1.0D);
}
}, Blocks.DOUBLE_PLANT);
itemcolors.registerItemColorHandler(new IItemColor()
{
public int colorMultiplier(ItemStack stack, int tintIndex)
{
if (tintIndex != 1)
{
return -1;
}
else
{
NBTBase nbtbase = ItemFireworkCharge.getExplosionTag(stack, "Colors");
if (!(nbtbase instanceof NBTTagIntArray))
{
return 9079434;
}
else
{
int[] aint = ((NBTTagIntArray)nbtbase).getIntArray();
if (aint.length == 1)
{
return aint[0];
}
else
{
int i = 0;
int j = 0;
int k = 0;
for (int l : aint)
{
i += (l & 16711680) >> 16;
j += (l & 65280) >> 8;
k += (l & 255) >> 0;
}
i = i / aint.length;
j = j / aint.length;
k = k / aint.length;
return i << 16 | j << 8 | k;
}
}
}
}
}, Items.FIREWORK_CHARGE);
itemcolors.registerItemColorHandler(new IItemColor()
{
public int colorMultiplier(ItemStack stack, int tintIndex)
{
return tintIndex > 0 ? -1 : PotionUtils.getColor(stack);
}
}, Items.POTIONITEM, Items.SPLASH_POTION, Items.LINGERING_POTION);
itemcolors.registerItemColorHandler(new IItemColor()
{
public int colorMultiplier(ItemStack stack, int tintIndex)
{
EntityList.EntityEggInfo entitylist$entityegginfo = EntityList.ENTITY_EGGS.get(ItemMonsterPlacer.getNamedIdFrom(stack));
if (entitylist$entityegginfo == null)
{
return -1;
}
else
{
return tintIndex == 0 ? entitylist$entityegginfo.primaryColor : entitylist$entityegginfo.secondaryColor;
}
}
}, Items.SPAWN_EGG);
itemcolors.registerItemColorHandler(new IItemColor()
{
public int colorMultiplier(ItemStack stack, int tintIndex)
{
IBlockState iblockstate = ((ItemBlock)stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata());
return colors.colorMultiplier(iblockstate, (IBlockAccess)null, (BlockPos)null, tintIndex);
}
}, Blocks.GRASS, Blocks.TALLGRASS, Blocks.VINE, Blocks.LEAVES, Blocks.LEAVES2, Blocks.WATERLILY);
itemcolors.registerItemColorHandler(new IItemColor()
{
public int colorMultiplier(ItemStack stack, int tintIndex)
{
return tintIndex == 0 ? PotionUtils.getColor(stack) : -1;
}
}, Items.TIPPED_ARROW);
itemcolors.registerItemColorHandler(new IItemColor()
{
public int colorMultiplier(ItemStack stack, int tintIndex)
{
return tintIndex == 0 ? -1 : ItemMap.getColor(stack);
}
}, Items.FILLED_MAP);
net.minecraftforge.client.ForgeHooksClient.onItemColorsInit(itemcolors, colors);
return itemcolors;
}
public int colorMultiplier(ItemStack stack, int tintIndex)
{
IItemColor iitemcolor = this.itemColorMap.get(stack.getItem().delegate);
return iitemcolor == null ? -1 : iitemcolor.colorMultiplier(stack, tintIndex);
}
public void registerItemColorHandler(IItemColor itemColor, Block... blocksIn)
{
for (Block block : blocksIn)
{
if (block == null) throw new IllegalArgumentException("Block registered to item color handler cannot be null!");
if (block.getRegistryName() == null) throw new IllegalArgumentException("Block must be registered before assigning color handler.");
this.itemColorMap.put(Item.getItemFromBlock(block).delegate, itemColor);
}
}
public void registerItemColorHandler(IItemColor itemColor, Item... itemsIn)
{
for (Item item : itemsIn)
{
if (item == null) throw new IllegalArgumentException("Item registered to item color handler cannot be null!");
if (item.getRegistryName() == null) throw new IllegalArgumentException("Item must be registered before assigning color handler.");
this.itemColorMap.put(item.delegate, itemColor);
}
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.client.renderer.color;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,36 @@
package net.minecraft.client.renderer.culling;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ClippingHelper
{
public float[][] frustum = new float[6][4];
public float[] projectionMatrix = new float[16];
public float[] modelviewMatrix = new float[16];
public float[] clippingMatrix = new float[16];
private double dot(float[] p_178624_1_, double p_178624_2_, double p_178624_4_, double p_178624_6_)
{
return (double)p_178624_1_[0] * p_178624_2_ + (double)p_178624_1_[1] * p_178624_4_ + (double)p_178624_1_[2] * p_178624_6_ + (double)p_178624_1_[3];
}
/**
* Returns true if the box is inside all 6 clipping planes, otherwise returns false.
*/
public boolean isBoxInFrustum(double p_78553_1_, double p_78553_3_, double p_78553_5_, double p_78553_7_, double p_78553_9_, double p_78553_11_)
{
for (int i = 0; i < 6; ++i)
{
float[] afloat = this.frustum[i];
if (this.dot(afloat, p_78553_1_, p_78553_3_, p_78553_5_) <= 0.0D && this.dot(afloat, p_78553_7_, p_78553_3_, p_78553_5_) <= 0.0D && this.dot(afloat, p_78553_1_, p_78553_9_, p_78553_5_) <= 0.0D && this.dot(afloat, p_78553_7_, p_78553_9_, p_78553_5_) <= 0.0D && this.dot(afloat, p_78553_1_, p_78553_3_, p_78553_11_) <= 0.0D && this.dot(afloat, p_78553_7_, p_78553_3_, p_78553_11_) <= 0.0D && this.dot(afloat, p_78553_1_, p_78553_9_, p_78553_11_) <= 0.0D && this.dot(afloat, p_78553_7_, p_78553_9_, p_78553_11_) <= 0.0D)
{
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,102 @@
package net.minecraft.client.renderer.culling;
import java.nio.FloatBuffer;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ClippingHelperImpl extends ClippingHelper
{
private static final ClippingHelperImpl instance = new ClippingHelperImpl();
private final FloatBuffer projectionMatrixBuffer = GLAllocation.createDirectFloatBuffer(16);
private final FloatBuffer modelviewMatrixBuffer = GLAllocation.createDirectFloatBuffer(16);
private final FloatBuffer floatBuffer16 = GLAllocation.createDirectFloatBuffer(16);
/**
* Initialises the ClippingHelper object then returns an instance of it.
*/
public static ClippingHelper getInstance()
{
instance.init();
return instance;
}
private void normalize(float[] p_180547_1_)
{
float f = MathHelper.sqrt(p_180547_1_[0] * p_180547_1_[0] + p_180547_1_[1] * p_180547_1_[1] + p_180547_1_[2] * p_180547_1_[2]);
p_180547_1_[0] /= f;
p_180547_1_[1] /= f;
p_180547_1_[2] /= f;
p_180547_1_[3] /= f;
}
public void init()
{
this.projectionMatrixBuffer.clear();
this.modelviewMatrixBuffer.clear();
this.floatBuffer16.clear();
GlStateManager.getFloat(2983, this.projectionMatrixBuffer);
GlStateManager.getFloat(2982, this.modelviewMatrixBuffer);
float[] afloat = this.projectionMatrix;
float[] afloat1 = this.modelviewMatrix;
this.projectionMatrixBuffer.flip().limit(16);
this.projectionMatrixBuffer.get(afloat);
this.modelviewMatrixBuffer.flip().limit(16);
this.modelviewMatrixBuffer.get(afloat1);
this.clippingMatrix[0] = afloat1[0] * afloat[0] + afloat1[1] * afloat[4] + afloat1[2] * afloat[8] + afloat1[3] * afloat[12];
this.clippingMatrix[1] = afloat1[0] * afloat[1] + afloat1[1] * afloat[5] + afloat1[2] * afloat[9] + afloat1[3] * afloat[13];
this.clippingMatrix[2] = afloat1[0] * afloat[2] + afloat1[1] * afloat[6] + afloat1[2] * afloat[10] + afloat1[3] * afloat[14];
this.clippingMatrix[3] = afloat1[0] * afloat[3] + afloat1[1] * afloat[7] + afloat1[2] * afloat[11] + afloat1[3] * afloat[15];
this.clippingMatrix[4] = afloat1[4] * afloat[0] + afloat1[5] * afloat[4] + afloat1[6] * afloat[8] + afloat1[7] * afloat[12];
this.clippingMatrix[5] = afloat1[4] * afloat[1] + afloat1[5] * afloat[5] + afloat1[6] * afloat[9] + afloat1[7] * afloat[13];
this.clippingMatrix[6] = afloat1[4] * afloat[2] + afloat1[5] * afloat[6] + afloat1[6] * afloat[10] + afloat1[7] * afloat[14];
this.clippingMatrix[7] = afloat1[4] * afloat[3] + afloat1[5] * afloat[7] + afloat1[6] * afloat[11] + afloat1[7] * afloat[15];
this.clippingMatrix[8] = afloat1[8] * afloat[0] + afloat1[9] * afloat[4] + afloat1[10] * afloat[8] + afloat1[11] * afloat[12];
this.clippingMatrix[9] = afloat1[8] * afloat[1] + afloat1[9] * afloat[5] + afloat1[10] * afloat[9] + afloat1[11] * afloat[13];
this.clippingMatrix[10] = afloat1[8] * afloat[2] + afloat1[9] * afloat[6] + afloat1[10] * afloat[10] + afloat1[11] * afloat[14];
this.clippingMatrix[11] = afloat1[8] * afloat[3] + afloat1[9] * afloat[7] + afloat1[10] * afloat[11] + afloat1[11] * afloat[15];
this.clippingMatrix[12] = afloat1[12] * afloat[0] + afloat1[13] * afloat[4] + afloat1[14] * afloat[8] + afloat1[15] * afloat[12];
this.clippingMatrix[13] = afloat1[12] * afloat[1] + afloat1[13] * afloat[5] + afloat1[14] * afloat[9] + afloat1[15] * afloat[13];
this.clippingMatrix[14] = afloat1[12] * afloat[2] + afloat1[13] * afloat[6] + afloat1[14] * afloat[10] + afloat1[15] * afloat[14];
this.clippingMatrix[15] = afloat1[12] * afloat[3] + afloat1[13] * afloat[7] + afloat1[14] * afloat[11] + afloat1[15] * afloat[15];
float[] afloat2 = this.frustum[0];
afloat2[0] = this.clippingMatrix[3] - this.clippingMatrix[0];
afloat2[1] = this.clippingMatrix[7] - this.clippingMatrix[4];
afloat2[2] = this.clippingMatrix[11] - this.clippingMatrix[8];
afloat2[3] = this.clippingMatrix[15] - this.clippingMatrix[12];
this.normalize(afloat2);
float[] afloat3 = this.frustum[1];
afloat3[0] = this.clippingMatrix[3] + this.clippingMatrix[0];
afloat3[1] = this.clippingMatrix[7] + this.clippingMatrix[4];
afloat3[2] = this.clippingMatrix[11] + this.clippingMatrix[8];
afloat3[3] = this.clippingMatrix[15] + this.clippingMatrix[12];
this.normalize(afloat3);
float[] afloat4 = this.frustum[2];
afloat4[0] = this.clippingMatrix[3] + this.clippingMatrix[1];
afloat4[1] = this.clippingMatrix[7] + this.clippingMatrix[5];
afloat4[2] = this.clippingMatrix[11] + this.clippingMatrix[9];
afloat4[3] = this.clippingMatrix[15] + this.clippingMatrix[13];
this.normalize(afloat4);
float[] afloat5 = this.frustum[3];
afloat5[0] = this.clippingMatrix[3] - this.clippingMatrix[1];
afloat5[1] = this.clippingMatrix[7] - this.clippingMatrix[5];
afloat5[2] = this.clippingMatrix[11] - this.clippingMatrix[9];
afloat5[3] = this.clippingMatrix[15] - this.clippingMatrix[13];
this.normalize(afloat5);
float[] afloat6 = this.frustum[4];
afloat6[0] = this.clippingMatrix[3] - this.clippingMatrix[2];
afloat6[1] = this.clippingMatrix[7] - this.clippingMatrix[6];
afloat6[2] = this.clippingMatrix[11] - this.clippingMatrix[10];
afloat6[3] = this.clippingMatrix[15] - this.clippingMatrix[14];
this.normalize(afloat6);
float[] afloat7 = this.frustum[5];
afloat7[0] = this.clippingMatrix[3] + this.clippingMatrix[2];
afloat7[1] = this.clippingMatrix[7] + this.clippingMatrix[6];
afloat7[2] = this.clippingMatrix[11] + this.clippingMatrix[10];
afloat7[3] = this.clippingMatrix[15] + this.clippingMatrix[14];
this.normalize(afloat7);
}
}

View File

@@ -0,0 +1,47 @@
package net.minecraft.client.renderer.culling;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Frustum implements ICamera
{
private final ClippingHelper clippingHelper;
private double x;
private double y;
private double z;
public Frustum()
{
this(ClippingHelperImpl.getInstance());
}
public Frustum(ClippingHelper clippingHelperIn)
{
this.clippingHelper = clippingHelperIn;
}
public void setPosition(double xIn, double yIn, double zIn)
{
this.x = xIn;
this.y = yIn;
this.z = zIn;
}
/**
* Calls the clipping helper. Returns true if the box is inside all 6 clipping planes, otherwise returns false.
*/
public boolean isBoxInFrustum(double p_78548_1_, double p_78548_3_, double p_78548_5_, double p_78548_7_, double p_78548_9_, double p_78548_11_)
{
return this.clippingHelper.isBoxInFrustum(p_78548_1_ - this.x, p_78548_3_ - this.y, p_78548_5_ - this.z, p_78548_7_ - this.x, p_78548_9_ - this.y, p_78548_11_ - this.z);
}
/**
* Returns true if the bounding box is inside all 6 clipping planes, otherwise returns false.
*/
public boolean isBoundingBoxInFrustum(AxisAlignedBB p_78546_1_)
{
return this.isBoxInFrustum(p_78546_1_.minX, p_78546_1_.minY, p_78546_1_.minZ, p_78546_1_.maxX, p_78546_1_.maxY, p_78546_1_.maxZ);
}
}

View File

@@ -0,0 +1,16 @@
package net.minecraft.client.renderer.culling;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface ICamera
{
/**
* Returns true if the bounding box is inside all 6 clipping planes, otherwise returns false.
*/
boolean isBoundingBoxInFrustum(AxisAlignedBB p_78546_1_);
void setPosition(double xIn, double yIn, double zIn);
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.client.renderer.culling;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,132 @@
package net.minecraft.client.renderer.debug;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class DebugRenderer
{
public final DebugRenderer.IDebugRenderer pathfinding;
public final DebugRenderer.IDebugRenderer water;
public final DebugRenderer.IDebugRenderer chunkBorder;
public final DebugRenderer.IDebugRenderer heightMap;
public final DebugRenderer.IDebugRenderer collisionBox;
public final DebugRenderer.IDebugRenderer neighborsUpdate;
public final DebugRenderer.IDebugRenderer solidFace;
private boolean chunkBorderEnabled;
private boolean pathfindingEnabled;
private boolean waterEnabled;
private boolean heightMapEnabled;
private boolean collisionBoxEnabled;
private boolean neighborsUpdateEnabled;
private boolean solidFaceEnabled;
public DebugRenderer(Minecraft clientIn)
{
this.pathfinding = new DebugRendererPathfinding(clientIn);
this.water = new DebugRendererWater(clientIn);
this.chunkBorder = new DebugRendererChunkBorder(clientIn);
this.heightMap = new DebugRendererHeightMap(clientIn);
this.collisionBox = new DebugRendererCollisionBox(clientIn);
this.neighborsUpdate = new DebugRendererNeighborsUpdate(clientIn);
this.solidFace = new DebugRendererSolidFace(clientIn);
}
public boolean shouldRender()
{
return this.chunkBorderEnabled || this.pathfindingEnabled || this.waterEnabled || this.heightMapEnabled || this.collisionBoxEnabled || this.neighborsUpdateEnabled || this.solidFaceEnabled;
}
/**
* Toggles the debug screen's visibility.
*/
public boolean toggleChunkBorders()
{
this.chunkBorderEnabled = !this.chunkBorderEnabled;
return this.chunkBorderEnabled;
}
public void renderDebug(float partialTicks, long finishTimeNano)
{
if (this.pathfindingEnabled)
{
this.pathfinding.render(partialTicks, finishTimeNano);
}
if (this.chunkBorderEnabled && !Minecraft.getMinecraft().isReducedDebug())
{
this.chunkBorder.render(partialTicks, finishTimeNano);
}
if (this.waterEnabled)
{
this.water.render(partialTicks, finishTimeNano);
}
if (this.heightMapEnabled)
{
this.heightMap.render(partialTicks, finishTimeNano);
}
if (this.collisionBoxEnabled)
{
this.collisionBox.render(partialTicks, finishTimeNano);
}
if (this.neighborsUpdateEnabled)
{
this.neighborsUpdate.render(partialTicks, finishTimeNano);
}
if (this.solidFaceEnabled)
{
this.solidFace.render(partialTicks, finishTimeNano);
}
}
public static void renderDebugText(String str, int x, int y, int z, float partialTicks, int color)
{
renderDebugText(str, (double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D, partialTicks, color);
}
public static void renderDebugText(String str, double x, double y, double z, float partialTicks, int color)
{
Minecraft minecraft = Minecraft.getMinecraft();
if (minecraft.player != null && minecraft.getRenderManager() != null && minecraft.getRenderManager().options != null)
{
FontRenderer fontrenderer = minecraft.fontRenderer;
EntityPlayer entityplayer = minecraft.player;
double d0 = entityplayer.lastTickPosX + (entityplayer.posX - entityplayer.lastTickPosX) * (double)partialTicks;
double d1 = entityplayer.lastTickPosY + (entityplayer.posY - entityplayer.lastTickPosY) * (double)partialTicks;
double d2 = entityplayer.lastTickPosZ + (entityplayer.posZ - entityplayer.lastTickPosZ) * (double)partialTicks;
GlStateManager.pushMatrix();
GlStateManager.translate((float)(x - d0), (float)(y - d1) + 0.07F, (float)(z - d2));
GlStateManager.glNormal3f(0.0F, 1.0F, 0.0F);
GlStateManager.scale(0.02F, -0.02F, 0.02F);
RenderManager rendermanager = minecraft.getRenderManager();
GlStateManager.rotate(-rendermanager.playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate((float)(rendermanager.options.thirdPersonView == 2 ? 1 : -1) * rendermanager.playerViewX, 1.0F, 0.0F, 0.0F);
GlStateManager.disableLighting();
GlStateManager.enableTexture2D();
GlStateManager.enableDepth();
GlStateManager.depthMask(true);
GlStateManager.scale(-1.0F, 1.0F, 1.0F);
fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, 0, color);
GlStateManager.enableLighting();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.popMatrix();
}
}
@SideOnly(Side.CLIENT)
public interface IDebugRenderer
{
void render(float partialTicks, long finishTimeNano);
}
}

View File

@@ -0,0 +1,118 @@
package net.minecraft.client.renderer.debug;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class DebugRendererChunkBorder implements DebugRenderer.IDebugRenderer
{
private final Minecraft minecraft;
public DebugRendererChunkBorder(Minecraft minecraftIn)
{
this.minecraft = minecraftIn;
}
public void render(float partialTicks, long finishTimeNano)
{
EntityPlayer entityplayer = this.minecraft.player;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
double d0 = entityplayer.lastTickPosX + (entityplayer.posX - entityplayer.lastTickPosX) * (double)partialTicks;
double d1 = entityplayer.lastTickPosY + (entityplayer.posY - entityplayer.lastTickPosY) * (double)partialTicks;
double d2 = entityplayer.lastTickPosZ + (entityplayer.posZ - entityplayer.lastTickPosZ) * (double)partialTicks;
double d3 = 0.0D - d1;
double d4 = 256.0D - d1;
GlStateManager.disableTexture2D();
GlStateManager.disableBlend();
double d5 = (double)(entityplayer.chunkCoordX << 4) - d0;
double d6 = (double)(entityplayer.chunkCoordZ << 4) - d2;
GlStateManager.glLineWidth(1.0F);
bufferbuilder.begin(3, DefaultVertexFormats.POSITION_COLOR);
for (int i = -16; i <= 32; i += 16)
{
for (int j = -16; j <= 32; j += 16)
{
bufferbuilder.pos(d5 + (double)i, d3, d6 + (double)j).color(1.0F, 0.0F, 0.0F, 0.0F).endVertex();
bufferbuilder.pos(d5 + (double)i, d3, d6 + (double)j).color(1.0F, 0.0F, 0.0F, 0.5F).endVertex();
bufferbuilder.pos(d5 + (double)i, d4, d6 + (double)j).color(1.0F, 0.0F, 0.0F, 0.5F).endVertex();
bufferbuilder.pos(d5 + (double)i, d4, d6 + (double)j).color(1.0F, 0.0F, 0.0F, 0.0F).endVertex();
}
}
for (int k = 2; k < 16; k += 2)
{
bufferbuilder.pos(d5 + (double)k, d3, d6).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
bufferbuilder.pos(d5 + (double)k, d3, d6).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + (double)k, d4, d6).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + (double)k, d4, d6).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
bufferbuilder.pos(d5 + (double)k, d3, d6 + 16.0D).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
bufferbuilder.pos(d5 + (double)k, d3, d6 + 16.0D).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + (double)k, d4, d6 + 16.0D).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + (double)k, d4, d6 + 16.0D).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
}
for (int l = 2; l < 16; l += 2)
{
bufferbuilder.pos(d5, d3, d6 + (double)l).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
bufferbuilder.pos(d5, d3, d6 + (double)l).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5, d4, d6 + (double)l).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5, d4, d6 + (double)l).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
bufferbuilder.pos(d5 + 16.0D, d3, d6 + (double)l).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
bufferbuilder.pos(d5 + 16.0D, d3, d6 + (double)l).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + 16.0D, d4, d6 + (double)l).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + 16.0D, d4, d6 + (double)l).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
}
for (int i1 = 0; i1 <= 256; i1 += 2)
{
double d7 = (double)i1 - d1;
bufferbuilder.pos(d5, d7, d6).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
bufferbuilder.pos(d5, d7, d6).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5, d7, d6 + 16.0D).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + 16.0D, d7, d6 + 16.0D).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + 16.0D, d7, d6).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5, d7, d6).color(1.0F, 1.0F, 0.0F, 1.0F).endVertex();
bufferbuilder.pos(d5, d7, d6).color(1.0F, 1.0F, 0.0F, 0.0F).endVertex();
}
tessellator.draw();
GlStateManager.glLineWidth(2.0F);
bufferbuilder.begin(3, DefaultVertexFormats.POSITION_COLOR);
for (int j1 = 0; j1 <= 16; j1 += 16)
{
for (int l1 = 0; l1 <= 16; l1 += 16)
{
bufferbuilder.pos(d5 + (double)j1, d3, d6 + (double)l1).color(0.25F, 0.25F, 1.0F, 0.0F).endVertex();
bufferbuilder.pos(d5 + (double)j1, d3, d6 + (double)l1).color(0.25F, 0.25F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + (double)j1, d4, d6 + (double)l1).color(0.25F, 0.25F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + (double)j1, d4, d6 + (double)l1).color(0.25F, 0.25F, 1.0F, 0.0F).endVertex();
}
}
for (int k1 = 0; k1 <= 256; k1 += 16)
{
double d8 = (double)k1 - d1;
bufferbuilder.pos(d5, d8, d6).color(0.25F, 0.25F, 1.0F, 0.0F).endVertex();
bufferbuilder.pos(d5, d8, d6).color(0.25F, 0.25F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos(d5, d8, d6 + 16.0D).color(0.25F, 0.25F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + 16.0D, d8, d6 + 16.0D).color(0.25F, 0.25F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos(d5 + 16.0D, d8, d6).color(0.25F, 0.25F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos(d5, d8, d6).color(0.25F, 0.25F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos(d5, d8, d6).color(0.25F, 0.25F, 1.0F, 0.0F).endVertex();
}
tessellator.draw();
GlStateManager.glLineWidth(1.0F);
GlStateManager.enableBlend();
GlStateManager.enableTexture2D();
}
}

View File

@@ -0,0 +1,50 @@
package net.minecraft.client.renderer.debug;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class DebugRendererCollisionBox implements DebugRenderer.IDebugRenderer
{
private final Minecraft minecraft;
private EntityPlayer player;
private double renderPosX;
private double renderPosY;
private double renderPosZ;
public DebugRendererCollisionBox(Minecraft minecraftIn)
{
this.minecraft = minecraftIn;
}
public void render(float partialTicks, long finishTimeNano)
{
this.player = this.minecraft.player;
this.renderPosX = this.player.lastTickPosX + (this.player.posX - this.player.lastTickPosX) * (double)partialTicks;
this.renderPosY = this.player.lastTickPosY + (this.player.posY - this.player.lastTickPosY) * (double)partialTicks;
this.renderPosZ = this.player.lastTickPosZ + (this.player.posZ - this.player.lastTickPosZ) * (double)partialTicks;
World world = this.minecraft.player.world;
List<AxisAlignedBB> list = world.getCollisionBoxes(this.player, this.player.getEntityBoundingBox().grow(6.0D));
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.glLineWidth(2.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
for (AxisAlignedBB axisalignedbb : list)
{
RenderGlobal.drawSelectionBoundingBox(axisalignedbb.grow(0.002D).offset(-this.renderPosX, -this.renderPosY, -this.renderPosZ), 1.0F, 1.0F, 1.0F, 1.0F);
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
}

View File

@@ -0,0 +1,61 @@
package net.minecraft.client.renderer.debug;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class DebugRendererHeightMap implements DebugRenderer.IDebugRenderer
{
private final Minecraft minecraft;
public DebugRendererHeightMap(Minecraft minecraftIn)
{
this.minecraft = minecraftIn;
}
public void render(float partialTicks, long finishTimeNano)
{
EntityPlayer entityplayer = this.minecraft.player;
World world = this.minecraft.world;
double d0 = entityplayer.lastTickPosX + (entityplayer.posX - entityplayer.lastTickPosX) * (double)partialTicks;
double d1 = entityplayer.lastTickPosY + (entityplayer.posY - entityplayer.lastTickPosY) * (double)partialTicks;
double d2 = entityplayer.lastTickPosZ + (entityplayer.posZ - entityplayer.lastTickPosZ) * (double)partialTicks;
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.disableTexture2D();
BlockPos blockpos = new BlockPos(entityplayer.posX, 0.0D, entityplayer.posZ);
Iterable<BlockPos> iterable = BlockPos.getAllInBox(blockpos.add(-40, 0, -40), blockpos.add(40, 0, 40));
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(5, DefaultVertexFormats.POSITION_COLOR);
for (BlockPos blockpos1 : iterable)
{
int i = world.getHeight(blockpos1.getX(), blockpos1.getZ());
if (world.getBlockState(blockpos1.add(0, i, 0).down()) == Blocks.AIR.getDefaultState())
{
RenderGlobal.addChainedFilledBoxVertices(bufferbuilder, (double)((float)blockpos1.getX() + 0.25F) - d0, (double)i - d1, (double)((float)blockpos1.getZ() + 0.25F) - d2, (double)((float)blockpos1.getX() + 0.75F) - d0, (double)i + 0.09375D - d1, (double)((float)blockpos1.getZ() + 0.75F) - d2, 0.0F, 0.0F, 1.0F, 0.5F);
}
else
{
RenderGlobal.addChainedFilledBoxVertices(bufferbuilder, (double)((float)blockpos1.getX() + 0.25F) - d0, (double)i - d1, (double)((float)blockpos1.getZ() + 0.25F) - d2, (double)((float)blockpos1.getX() + 0.75F) - d0, (double)i + 0.09375D - d1, (double)((float)blockpos1.getZ() + 0.75F) - d2, 0.0F, 1.0F, 0.0F, 0.5F);
}
}
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
}
}

Some files were not shown because too many files have changed in this diff Show More