pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,8 +18,6 @@
|
||||
|
||||
package appeng.client.render;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -31,108 +29,107 @@ import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.IWideReadableNumberConverter;
|
||||
import appeng.util.ReadableNumberConverter;
|
||||
|
||||
|
||||
/**
|
||||
* Helper methods for rendering TESRs.
|
||||
*/
|
||||
public class TesrRenderHelper
|
||||
{
|
||||
public class TesrRenderHelper {
|
||||
|
||||
private static final IWideReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
|
||||
private static final IWideReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
|
||||
|
||||
/**
|
||||
* Rotate the current coordinate system so it is on the face of the given block side. This can be used to render on
|
||||
* the given face as if it was
|
||||
* a 2D canvas.
|
||||
*/
|
||||
public static void rotateToFace( MatrixStack mStack, Direction face, byte spin )
|
||||
{
|
||||
switch( face )
|
||||
{
|
||||
case UP:
|
||||
mStack.rotate( Vector3f.XP.rotationDegrees( 90.0F ) );
|
||||
mStack.rotate( Vector3f.ZP.rotationDegrees( spin * 90.0F ) );
|
||||
break;
|
||||
/**
|
||||
* Rotate the current coordinate system so it is on the face of the given block
|
||||
* side. This can be used to render on the given face as if it was a 2D canvas.
|
||||
*/
|
||||
public static void rotateToFace(MatrixStack mStack, Direction face, byte spin) {
|
||||
switch (face) {
|
||||
case UP:
|
||||
mStack.rotate(Vector3f.XP.rotationDegrees(90.0F));
|
||||
mStack.rotate(Vector3f.ZP.rotationDegrees(spin * 90.0F));
|
||||
break;
|
||||
|
||||
case DOWN:
|
||||
mStack.rotate( Vector3f.XP.rotationDegrees( -90.0F ) );
|
||||
mStack.rotate( Vector3f.ZP.rotationDegrees( spin * -90.0F ) );
|
||||
break;
|
||||
case DOWN:
|
||||
mStack.rotate(Vector3f.XP.rotationDegrees(-90.0F));
|
||||
mStack.rotate(Vector3f.ZP.rotationDegrees(spin * -90.0F));
|
||||
break;
|
||||
|
||||
case EAST:
|
||||
mStack.rotate( Vector3f.YP.rotationDegrees( 90.0F ) );
|
||||
break;
|
||||
case EAST:
|
||||
mStack.rotate(Vector3f.YP.rotationDegrees(90.0F));
|
||||
break;
|
||||
|
||||
case WEST:
|
||||
mStack.rotate( Vector3f.YP.rotationDegrees( -90.0F ) );
|
||||
break;
|
||||
case WEST:
|
||||
mStack.rotate(Vector3f.YP.rotationDegrees(-90.0F));
|
||||
break;
|
||||
|
||||
case NORTH:
|
||||
mStack.rotate( Vector3f.YP.rotationDegrees( 180.0F ) );
|
||||
break;
|
||||
case NORTH:
|
||||
mStack.rotate(Vector3f.YP.rotationDegrees(180.0F));
|
||||
break;
|
||||
|
||||
case SOUTH:
|
||||
break;
|
||||
case SOUTH:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO, A different approach will have to be used for this from TESRs, -covers, i have ideas.
|
||||
/**
|
||||
* Render an item in 2D.
|
||||
*/
|
||||
public static void renderItem2d(MatrixStack matrixStack, IRenderTypeBuffer buffers, ItemStack itemStack, float scale, int combinedLightIn, int combinedOverlayIn)
|
||||
{
|
||||
if( !itemStack.isEmpty() )
|
||||
{
|
||||
matrixStack.push();
|
||||
// Push it out of the block face a bit to avoid z-fighting
|
||||
matrixStack.translate(0, 0, 0.01f);
|
||||
// The Z-scaling by 0.0002 causes the model to be visually "flattened"
|
||||
// This cannot replace a proper projection, but it's cheap and gives the desired
|
||||
// effect at least from head-on
|
||||
matrixStack.scale( scale, scale, 0.0002f );
|
||||
// TODO, A different approach will have to be used for this from TESRs, -covers,
|
||||
// i have ideas.
|
||||
/**
|
||||
* Render an item in 2D.
|
||||
*/
|
||||
public static void renderItem2d(MatrixStack matrixStack, IRenderTypeBuffer buffers, ItemStack itemStack,
|
||||
float scale, int combinedLightIn, int combinedOverlayIn) {
|
||||
if (!itemStack.isEmpty()) {
|
||||
matrixStack.push();
|
||||
// Push it out of the block face a bit to avoid z-fighting
|
||||
matrixStack.translate(0, 0, 0.01f);
|
||||
// The Z-scaling by 0.0002 causes the model to be visually "flattened"
|
||||
// This cannot replace a proper projection, but it's cheap and gives the desired
|
||||
// effect at least from head-on
|
||||
matrixStack.scale(scale, scale, 0.0002f);
|
||||
|
||||
Minecraft.getInstance().getItemRenderer().renderItem(itemStack, ItemCameraTransforms.TransformType.GUI, combinedLightIn, OverlayTexture.NO_OVERLAY, matrixStack, buffers);
|
||||
Minecraft.getInstance().getItemRenderer().renderItem(itemStack, ItemCameraTransforms.TransformType.GUI,
|
||||
combinedLightIn, OverlayTexture.NO_OVERLAY, matrixStack, buffers);
|
||||
|
||||
matrixStack.pop();
|
||||
matrixStack.pop();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an item in 2D and the given text below it.
|
||||
* @param matrixStack
|
||||
* @param buffers
|
||||
* @param spacing Specifies how far apart the item and the item stack amount are rendered.
|
||||
* @param combinedLightIn
|
||||
* @param combinedOverlayIn
|
||||
*/
|
||||
public static void renderItem2dWithAmount(MatrixStack matrixStack, IRenderTypeBuffer buffers, IAEItemStack itemStack, float itemScale, float spacing, int combinedLightIn, int combinedOverlayIn)
|
||||
{
|
||||
final ItemStack renderStack = itemStack.asItemStackRepresentation();
|
||||
/**
|
||||
* Render an item in 2D and the given text below it.
|
||||
*
|
||||
* @param matrixStack
|
||||
* @param buffers
|
||||
* @param spacing Specifies how far apart the item and the item stack
|
||||
* amount are rendered.
|
||||
* @param combinedLightIn
|
||||
* @param combinedOverlayIn
|
||||
*/
|
||||
public static void renderItem2dWithAmount(MatrixStack matrixStack, IRenderTypeBuffer buffers,
|
||||
IAEItemStack itemStack, float itemScale, float spacing, int combinedLightIn, int combinedOverlayIn) {
|
||||
final ItemStack renderStack = itemStack.asItemStackRepresentation();
|
||||
|
||||
TesrRenderHelper.renderItem2d( matrixStack, buffers, renderStack, itemScale, combinedLightIn, combinedOverlayIn );
|
||||
TesrRenderHelper.renderItem2d(matrixStack, buffers, renderStack, itemScale, combinedLightIn, combinedOverlayIn);
|
||||
|
||||
final long stackSize = itemStack.getStackSize();
|
||||
final String renderedStackSize = NUMBER_CONVERTER.toWideReadableForm( stackSize );
|
||||
final long stackSize = itemStack.getStackSize();
|
||||
final String renderedStackSize = NUMBER_CONVERTER.toWideReadableForm(stackSize);
|
||||
|
||||
// Render the item count
|
||||
final FontRenderer fr = Minecraft.getInstance().fontRenderer;
|
||||
final int width = fr.getStringWidth( renderedStackSize );
|
||||
matrixStack.push();
|
||||
matrixStack.translate( 0.0f, spacing, 0.02f );
|
||||
matrixStack.scale( 1.0f / 62.0f, - 1.0f / 62.0f, 1.0f / 62.0f );
|
||||
matrixStack.scale(0.5f, 0.5f, 0);
|
||||
matrixStack.translate( -0.5f * width, 0.0f, 0.5f );
|
||||
fr.renderString(renderedStackSize, 0, 0, -1, false, matrixStack.getLast().getMatrix(), buffers, false, 0, 15728880);
|
||||
matrixStack.pop();
|
||||
// Render the item count
|
||||
final FontRenderer fr = Minecraft.getInstance().fontRenderer;
|
||||
final int width = fr.getStringWidth(renderedStackSize);
|
||||
matrixStack.push();
|
||||
matrixStack.translate(0.0f, spacing, 0.02f);
|
||||
matrixStack.scale(1.0f / 62.0f, -1.0f / 62.0f, 1.0f / 62.0f);
|
||||
matrixStack.scale(0.5f, 0.5f, 0);
|
||||
matrixStack.translate(-0.5f * width, 0.0f, 0.5f);
|
||||
fr.renderString(renderedStackSize, 0, 0, -1, false, matrixStack.getLast().getMatrix(), buffers, false, 0,
|
||||
15728880);
|
||||
matrixStack.pop();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user