mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-10-31 23:26:19 +00:00
Add back map rendering
Closes #357. Also bump Forge and mappings versions - it includes a couple of bug fixes we need.
This commit is contained in:
parent
649acbae1c
commit
f4f71185ae
@ -9,7 +9,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.google.code.gson:gson:2.8.1'
|
classpath 'com.google.code.gson:gson:2.8.1'
|
||||||
classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.159'
|
classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.169'
|
||||||
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2'
|
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2'
|
||||||
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@ mod_version=1.86.2
|
|||||||
|
|
||||||
# Minecraft properties (update mods.toml when changing)
|
# Minecraft properties (update mods.toml when changing)
|
||||||
mc_version=1.15.2
|
mc_version=1.15.2
|
||||||
forge_version=31.0.13
|
forge_version=31.1.41
|
||||||
mappings_version=20200124-1.15.1
|
mappings_version=20200410-1.15.1
|
||||||
|
@ -76,7 +76,7 @@ public final class ClientRegistry
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
||||||
{
|
{
|
||||||
if( !event.getMap().getBasePath().equals( PlayerContainer.LOCATION_BLOCKS_TEXTURE ) ) return;
|
if( !event.getMap().getTextureLocation().equals( PlayerContainer.LOCATION_BLOCKS_TEXTURE ) ) return;
|
||||||
|
|
||||||
for( String extra : EXTRA_TEXTURES )
|
for( String extra : EXTRA_TEXTURES )
|
||||||
{
|
{
|
||||||
|
@ -254,7 +254,7 @@ public final class FixedWidthFontRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminal(
|
public static void drawTerminal(
|
||||||
float x, float y, @Nonnull Terminal terminal, boolean greyscale,
|
@Nonnull Matrix4f transform, float x, float y, @Nonnull Terminal terminal, boolean greyscale,
|
||||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -264,26 +264,39 @@ public final class FixedWidthFontRenderer
|
|||||||
|
|
||||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||||
IVertexBuilder buffer = renderer.getBuffer( TYPE );
|
IVertexBuilder buffer = renderer.getBuffer( TYPE );
|
||||||
drawTerminal( IDENTITY, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||||
renderer.finish( TYPE );
|
renderer.finish( TYPE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void drawTerminal(
|
||||||
|
float x, float y, @Nonnull Terminal terminal, boolean greyscale,
|
||||||
|
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||||
|
)
|
||||||
|
{
|
||||||
|
drawTerminal( IDENTITY, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||||
|
}
|
||||||
|
|
||||||
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull IRenderTypeBuffer renderer, float x, float y, float width, float height )
|
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull IRenderTypeBuffer renderer, float x, float y, float width, float height )
|
||||||
{
|
{
|
||||||
Colour colour = Colour.BLACK;
|
Colour colour = Colour.BLACK;
|
||||||
drawQuad( transform, renderer.getBuffer( TYPE ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
drawQuad( transform, renderer.getBuffer( TYPE ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawEmptyTerminal( float x, float y, float width, float height )
|
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, float x, float y, float width, float height )
|
||||||
{
|
{
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( FONT );
|
Minecraft.getInstance().getTextureManager().bindTexture( FONT );
|
||||||
RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
||||||
|
|
||||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||||
drawEmptyTerminal( IDENTITY, renderer, x, y, width, height );
|
drawEmptyTerminal( transform, renderer, x, y, width, height );
|
||||||
renderer.finish();
|
renderer.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void drawEmptyTerminal( float x, float y, float width, float height )
|
||||||
|
{
|
||||||
|
drawEmptyTerminal( IDENTITY, x, y, width, height );
|
||||||
|
}
|
||||||
|
|
||||||
public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull IRenderTypeBuffer renderer, float x, float y, float width, float height )
|
public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull IRenderTypeBuffer renderer, float x, float y, float width, float height )
|
||||||
{
|
{
|
||||||
Colour colour = Colour.BLACK;
|
Colour colour = Colour.BLACK;
|
||||||
@ -296,10 +309,10 @@ public final class FixedWidthFontRenderer
|
|||||||
|
|
||||||
private static final VertexFormat FORMAT = DefaultVertexFormats.POSITION_COLOR_TEX;
|
private static final VertexFormat FORMAT = DefaultVertexFormats.POSITION_COLOR_TEX;
|
||||||
|
|
||||||
static final RenderType MAIN = RenderType.get(
|
static final RenderType MAIN = RenderType.makeType(
|
||||||
"terminal_font", FORMAT, GL_MODE, 1024,
|
"terminal_font", FORMAT, GL_MODE, 1024,
|
||||||
false, false, // useDelegate, needsSorting
|
false, false, // useDelegate, needsSorting
|
||||||
RenderType.State.builder()
|
RenderType.State.getBuilder()
|
||||||
.texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
.texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
||||||
.alpha( DEFAULT_ALPHA )
|
.alpha( DEFAULT_ALPHA )
|
||||||
.lightmap( LIGHTMAP_DISABLED )
|
.lightmap( LIGHTMAP_DISABLED )
|
||||||
@ -307,10 +320,10 @@ public final class FixedWidthFontRenderer
|
|||||||
.build( false )
|
.build( false )
|
||||||
);
|
);
|
||||||
|
|
||||||
static final RenderType BLOCKER = RenderType.get(
|
static final RenderType BLOCKER = RenderType.makeType(
|
||||||
"terminal_blocker", FORMAT, GL_MODE, 256,
|
"terminal_blocker", FORMAT, GL_MODE, 256,
|
||||||
false, false, // useDelegate, needsSorting
|
false, false, // useDelegate, needsSorting
|
||||||
RenderType.State.builder()
|
RenderType.State.getBuilder()
|
||||||
.texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
.texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
||||||
.alpha( DEFAULT_ALPHA )
|
.alpha( DEFAULT_ALPHA )
|
||||||
.writeMask( DEPTH_WRITE )
|
.writeMask( DEPTH_WRITE )
|
||||||
|
@ -38,12 +38,12 @@ public final class ComputerCraftProxyClient
|
|||||||
registerContainers();
|
registerContainers();
|
||||||
|
|
||||||
// While turtles themselves are not transparent, their upgrades may be.
|
// While turtles themselves are not transparent, their upgrades may be.
|
||||||
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleNormal, RenderType.translucent() );
|
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleNormal, RenderType.getTranslucent() );
|
||||||
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleAdvanced, RenderType.translucent() );
|
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleAdvanced, RenderType.getTranslucent() );
|
||||||
|
|
||||||
// Monitors' textures have transparent fronts and so count as cutouts.
|
// Monitors' textures have transparent fronts and so count as cutouts.
|
||||||
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorNormal, RenderType.cutout() );
|
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorNormal, RenderType.getCutout() );
|
||||||
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorAdvanced, RenderType.cutout() );
|
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorAdvanced, RenderType.getCutout() );
|
||||||
|
|
||||||
// Setup TESRs
|
// Setup TESRs
|
||||||
ClientRegistry.bindTileEntityRenderer( TileMonitor.FACTORY_NORMAL, TileEntityMonitorRenderer::new );
|
ClientRegistry.bindTileEntityRenderer( TileMonitor.FACTORY_NORMAL, TileEntityMonitorRenderer::new );
|
||||||
|
@ -67,8 +67,8 @@ public final class CableHighlightRenderer
|
|||||||
double yOffset = pos.getY() - cameraPos.getY();
|
double yOffset = pos.getY() - cameraPos.getY();
|
||||||
double zOffset = pos.getZ() - cameraPos.getZ();
|
double zOffset = pos.getZ() - cameraPos.getZ();
|
||||||
|
|
||||||
IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.lines() );
|
IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.getLines() );
|
||||||
Matrix4f matrix4f = event.getMatrix().getLast().getPositionMatrix();
|
Matrix4f matrix4f = event.getMatrix().getLast().getMatrix();
|
||||||
shape.forEachEdge( ( x1, y1, z1, x2, y2, z2 ) -> {
|
shape.forEachEdge( ( x1, y1, z1, x2, y2, z2 ) -> {
|
||||||
buffer.pos( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) )
|
buffer.pos( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) )
|
||||||
.color( 0, 0, 0, 0.4f ).endVertex();
|
.color( 0, 0, 0, 0.4f ).endVertex();
|
||||||
|
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
|
import dan200.computercraft.shared.util.Colour;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.*;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.client.event.RenderHandEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
|
import static dan200.computercraft.client.gui.GuiComputer.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emulates map rendering for pocket computers.
|
||||||
|
*/
|
||||||
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
||||||
|
public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||||
|
{
|
||||||
|
private static final int MARGIN = 2;
|
||||||
|
private static final int FRAME = 12;
|
||||||
|
private static final int LIGHT_HEIGHT = 8;
|
||||||
|
|
||||||
|
private static final ItemPocketRenderer INSTANCE = new ItemPocketRenderer();
|
||||||
|
|
||||||
|
private ItemPocketRenderer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRenderInHand( RenderHandEvent event )
|
||||||
|
{
|
||||||
|
ItemStack stack = event.getItemStack();
|
||||||
|
if( !(stack.getItem() instanceof ItemPocketComputer) ) return;
|
||||||
|
|
||||||
|
event.setCanceled( true );
|
||||||
|
INSTANCE.renderItemFirstPerson(
|
||||||
|
event.getMatrixStack(), event.getBuffers(), event.getLight(),
|
||||||
|
event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack )
|
||||||
|
{
|
||||||
|
ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
|
||||||
|
Terminal terminal = computer == null ? null : computer.getTerminal();
|
||||||
|
|
||||||
|
int termWidth, termHeight;
|
||||||
|
if( terminal == null )
|
||||||
|
{
|
||||||
|
termWidth = ComputerCraft.terminalWidth_pocketComputer;
|
||||||
|
termHeight = ComputerCraft.terminalHeight_pocketComputer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
termWidth = terminal.getWidth();
|
||||||
|
termHeight = terminal.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
int width = termWidth * FONT_WIDTH + MARGIN * 2;
|
||||||
|
int height = termHeight * FONT_HEIGHT + MARGIN * 2;
|
||||||
|
|
||||||
|
// Setup various transformations. Note that these are partially adapted from the corresponding method
|
||||||
|
// in ItemRenderer
|
||||||
|
transform.push();
|
||||||
|
transform.rotate( Vector3f.YP.rotationDegrees( 180f ) );
|
||||||
|
transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) );
|
||||||
|
transform.scale( 0.5f, 0.5f, 0.5f );
|
||||||
|
|
||||||
|
float scale = 0.75f / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT );
|
||||||
|
transform.scale( scale, scale, 0 );
|
||||||
|
transform.translate( -0.5 * width, -0.5 * height, 0 );
|
||||||
|
|
||||||
|
// Render the main frame
|
||||||
|
ItemPocketComputer item = (ItemPocketComputer) stack.getItem();
|
||||||
|
ComputerFamily family = item.getFamily();
|
||||||
|
int frameColour = item.getColour( stack );
|
||||||
|
|
||||||
|
Matrix4f matrix = transform.getLast().getMatrix();
|
||||||
|
renderFrame( matrix, family, frameColour, width, height );
|
||||||
|
|
||||||
|
// Render the light
|
||||||
|
int lightColour = ItemPocketComputer.getLightState( stack );
|
||||||
|
if( lightColour == -1 ) lightColour = Colour.BLACK.getHex();
|
||||||
|
renderLight( matrix, lightColour, width, height );
|
||||||
|
|
||||||
|
if( computer != null && terminal != null )
|
||||||
|
{
|
||||||
|
FixedWidthFontRenderer.drawTerminal( matrix, MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FixedWidthFontRenderer.drawEmptyTerminal( matrix, 0, 0, width, height );
|
||||||
|
}
|
||||||
|
|
||||||
|
transform.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderFrame( Matrix4f transform, ComputerFamily family, int colour, int width, int height )
|
||||||
|
{
|
||||||
|
Minecraft.getInstance().getTextureManager().bindTexture( colour != -1
|
||||||
|
? BACKGROUND_COLOUR
|
||||||
|
: family == ComputerFamily.NORMAL ? BACKGROUND_NORMAL : BACKGROUND_ADVANCED
|
||||||
|
);
|
||||||
|
|
||||||
|
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
||||||
|
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
||||||
|
float b = (colour & 0xFF) / 255.0f;
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
|
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX );
|
||||||
|
|
||||||
|
// Top left, middle, right
|
||||||
|
renderTexture( transform, buffer, -FRAME, -FRAME, 12, 28, FRAME, FRAME, r, g, b );
|
||||||
|
renderTexture( transform, buffer, 0, -FRAME, 0, 0, width, FRAME, r, g, b );
|
||||||
|
renderTexture( transform, buffer, width, -FRAME, 24, 28, FRAME, FRAME, r, g, b );
|
||||||
|
|
||||||
|
// Left and bright border
|
||||||
|
renderTexture( transform, buffer, -FRAME, 0, 0, 28, FRAME, height, r, g, b );
|
||||||
|
renderTexture( transform, buffer, width, 0, 36, 28, FRAME, height, r, g, b );
|
||||||
|
|
||||||
|
// Bottom left, middle, right. We do this in three portions: the top inner corners, an extended region for
|
||||||
|
// lights, and then the bottom outer corners.
|
||||||
|
renderTexture( transform, buffer, -FRAME, height, 12, 40, FRAME, FRAME / 2, r, g, b );
|
||||||
|
renderTexture( transform, buffer, 0, height, 0, 12, width, FRAME / 2, r, g, b );
|
||||||
|
renderTexture( transform, buffer, width, height, 24, 40, FRAME, FRAME / 2, r, g, b );
|
||||||
|
|
||||||
|
renderTexture( transform, buffer, -FRAME, height + FRAME / 2, 12, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
||||||
|
renderTexture( transform, buffer, 0, height + FRAME / 2, 0, 16, width, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
||||||
|
renderTexture( transform, buffer, width, height + FRAME / 2, 24, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
||||||
|
|
||||||
|
renderTexture( transform, buffer, -FRAME, height + LIGHT_HEIGHT + FRAME / 2, 12, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b );
|
||||||
|
renderTexture( transform, buffer, 0, height + LIGHT_HEIGHT + FRAME / 2, 0, 12 + FRAME / 2, width, FRAME / 2, r, g, b );
|
||||||
|
renderTexture( transform, buffer, width, height + LIGHT_HEIGHT + FRAME / 2, 24, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b );
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderLight( Matrix4f transform, int colour, int width, int height )
|
||||||
|
{
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.disableTexture();
|
||||||
|
|
||||||
|
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
||||||
|
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
||||||
|
float b = (colour & 0xFF) / 255.0f;
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
|
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR );
|
||||||
|
buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + FRAME / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||||
|
buffer.pos( transform, width, height + LIGHT_HEIGHT + FRAME / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||||
|
buffer.pos( transform, width, height + FRAME / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||||
|
buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
RenderSystem.enableTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderTexture( Matrix4f transform, IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, float r, float g, float b )
|
||||||
|
{
|
||||||
|
renderTexture( transform, builder, x, y, textureX, textureY, width, height, width, height, r, g, b );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderTexture( Matrix4f transform, IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, int textureWidth, int textureHeight, float r, float g, float b )
|
||||||
|
{
|
||||||
|
float scale = 1 / 255.0f;
|
||||||
|
builder.pos( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).tex( textureX * scale, (textureY + textureHeight) * scale ).endVertex();
|
||||||
|
builder.pos( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).tex( (textureX + textureWidth) * scale, (textureY + textureHeight) * scale ).endVertex();
|
||||||
|
builder.pos( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).tex( (textureX + textureWidth) * scale, textureY * scale ).endVertex();
|
||||||
|
builder.pos( transform, x, y, 0 ).color( r, g, b, 1.0f ).tex( textureX * scale, textureY * scale ).endVertex();
|
||||||
|
}
|
||||||
|
}
|
@ -36,7 +36,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: @SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onRenderInHand( RenderHandEvent event )
|
public static void onRenderInHand( RenderHandEvent event )
|
||||||
{
|
{
|
||||||
ItemStack stack = event.getItemStack();
|
ItemStack stack = event.getItemStack();
|
||||||
@ -53,7 +53,6 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack )
|
protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack )
|
||||||
{
|
{
|
||||||
transform.rotate( Vector3f.XP.rotationDegrees( 180f ) );
|
transform.rotate( Vector3f.XP.rotationDegrees( 180f ) );
|
||||||
transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) );
|
|
||||||
transform.scale( 0.42f, 0.42f, -0.42f );
|
transform.scale( 0.42f, 0.42f, -0.42f );
|
||||||
transform.translate( -0.5f, -0.48f, 0.0f );
|
transform.translate( -0.5f, -0.48f, 0.0f );
|
||||||
|
|
||||||
@ -105,7 +104,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
transform.scale( scale, scale, scale );
|
transform.scale( scale, scale, scale );
|
||||||
transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 );
|
transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 );
|
||||||
|
|
||||||
Matrix4f matrix = transform.getLast().getPositionMatrix();
|
Matrix4f matrix = transform.getLast().getMatrix();
|
||||||
drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book );
|
drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book );
|
||||||
drawText( matrix, render,
|
drawText( matrix, render,
|
||||||
X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack )
|
X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack )
|
||||||
|
@ -66,8 +66,8 @@ public final class MonitorHighlightRenderer
|
|||||||
transformStack.translate( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() );
|
transformStack.translate( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() );
|
||||||
|
|
||||||
// I wish I could think of a better way to do this
|
// I wish I could think of a better way to do this
|
||||||
IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.lines() );
|
IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.getLines() );
|
||||||
Matrix4f transform = transformStack.getLast().getPositionMatrix();
|
Matrix4f transform = transformStack.getLast().getMatrix();
|
||||||
if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 0, UP );
|
if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 0, UP );
|
||||||
if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 1, UP );
|
if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 1, UP );
|
||||||
if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, transform, 1, 0, 0, UP );
|
if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, transform, 1, 0, 0, UP );
|
||||||
|
@ -167,10 +167,10 @@ public final class PrintoutRenderer
|
|||||||
|
|
||||||
private static final class Type extends RenderState
|
private static final class Type extends RenderState
|
||||||
{
|
{
|
||||||
static final RenderType TYPE = RenderType.get(
|
static final RenderType TYPE = RenderType.makeType(
|
||||||
"printout_background", DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 1024,
|
"printout_background", DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 1024,
|
||||||
false, false, // useDelegate, needsSorting
|
false, false, // useDelegate, needsSorting
|
||||||
RenderType.State.builder()
|
RenderType.State.getBuilder()
|
||||||
.texture( new RenderState.TextureState( BG, false, false ) ) // blur, minimap
|
.texture( new RenderState.TextureState( BG, false, false ) ) // blur, minimap
|
||||||
.alpha( DEFAULT_ALPHA )
|
.alpha( DEFAULT_ALPHA )
|
||||||
.lightmap( LIGHTMAP_DISABLED )
|
.lightmap( LIGHTMAP_DISABLED )
|
||||||
|
@ -106,13 +106,13 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
float xMargin = (float) (MARGIN / xScale);
|
float xMargin = (float) (MARGIN / xScale);
|
||||||
float yMargin = (float) (MARGIN / yScale);
|
float yMargin = (float) (MARGIN / yScale);
|
||||||
|
|
||||||
Matrix4f matrix = transform.getLast().getPositionMatrix();
|
Matrix4f matrix = transform.getLast().getMatrix();
|
||||||
|
|
||||||
if( redraw )
|
if( redraw )
|
||||||
{
|
{
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder builder = tessellator.getBuffer();
|
BufferBuilder builder = tessellator.getBuffer();
|
||||||
builder.begin( FixedWidthFontRenderer.TYPE.getGlMode(), FixedWidthFontRenderer.TYPE.getVertexFormat() );
|
builder.begin( FixedWidthFontRenderer.TYPE.getDrawMode(), FixedWidthFontRenderer.TYPE.getVertexFormat() );
|
||||||
FixedWidthFontRenderer.drawTerminalWithoutCursor(
|
FixedWidthFontRenderer.drawTerminalWithoutCursor(
|
||||||
IDENTITY, builder, 0, 0,
|
IDENTITY, builder, 0, 0,
|
||||||
terminal, !originTerminal.isColour(), yMargin, yMargin, xMargin, xMargin
|
terminal, !originTerminal.isColour(), yMargin, yMargin, xMargin, xMargin
|
||||||
@ -126,11 +126,11 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
// render state. I've no clue how well this'll work in future versions of Minecraft, but it does the trick
|
// render state. I've no clue how well this'll work in future versions of Minecraft, but it does the trick
|
||||||
// for now.
|
// for now.
|
||||||
IVertexBuilder buffer = renderer.getBuffer( FixedWidthFontRenderer.TYPE );
|
IVertexBuilder buffer = renderer.getBuffer( FixedWidthFontRenderer.TYPE );
|
||||||
FixedWidthFontRenderer.TYPE.enable();
|
FixedWidthFontRenderer.TYPE.setupRenderState();
|
||||||
|
|
||||||
vbo.bindBuffer();
|
vbo.bindBuffer();
|
||||||
FixedWidthFontRenderer.TYPE.getVertexFormat().setupBufferState( 0L );
|
FixedWidthFontRenderer.TYPE.getVertexFormat().setupBufferState( 0L );
|
||||||
vbo.draw( matrix, FixedWidthFontRenderer.TYPE.getGlMode() );
|
vbo.draw( matrix, FixedWidthFontRenderer.TYPE.getDrawMode() );
|
||||||
VertexBuffer.unbindBuffer();
|
VertexBuffer.unbindBuffer();
|
||||||
FixedWidthFontRenderer.TYPE.getVertexFormat().clearBufferState();
|
FixedWidthFontRenderer.TYPE.getVertexFormat().clearBufferState();
|
||||||
|
|
||||||
@ -143,14 +143,14 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
FixedWidthFontRenderer.drawEmptyTerminal(
|
FixedWidthFontRenderer.drawEmptyTerminal(
|
||||||
transform.getLast().getPositionMatrix(), renderer,
|
transform.getLast().getMatrix(), renderer,
|
||||||
-MARGIN, MARGIN,
|
-MARGIN, MARGIN,
|
||||||
(float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2)
|
(float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedWidthFontRenderer.drawBlocker(
|
FixedWidthFontRenderer.drawBlocker(
|
||||||
transform.getLast().getPositionMatrix(), renderer,
|
transform.getLast().getMatrix(), renderer,
|
||||||
(float) -TileMonitor.RENDER_MARGIN, (float) TileMonitor.RENDER_MARGIN,
|
(float) -TileMonitor.RENDER_MARGIN, (float) TileMonitor.RENDER_MARGIN,
|
||||||
(float) (xSize + 2 * TileMonitor.RENDER_MARGIN), (float) -(ySize + TileMonitor.RENDER_MARGIN * 2)
|
(float) (xSize + 2 * TileMonitor.RENDER_MARGIN), (float) -(ySize + TileMonitor.RENDER_MARGIN * 2)
|
||||||
);
|
);
|
||||||
|
@ -87,7 +87,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
transform.rotate( mc.getRenderManager().getCameraOrientation() );
|
transform.rotate( mc.getRenderManager().getCameraOrientation() );
|
||||||
transform.scale( -0.025f, -0.025f, 0.025f );
|
transform.scale( -0.025f, -0.025f, 0.025f );
|
||||||
|
|
||||||
Matrix4f matrix = transform.getLast().getPositionMatrix();
|
Matrix4f matrix = transform.getLast().getMatrix();
|
||||||
int opacity = (int) (mc.gameSettings.getTextBackgroundOpacity( 0.25f ) * 255) << 24;
|
int opacity = (int) (mc.gameSettings.getTextBackgroundOpacity( 0.25f ) * 255) << 24;
|
||||||
float width = -font.getStringWidth( label ) / 2.0f;
|
float width = -font.getStringWidth( label ) / 2.0f;
|
||||||
font.renderString( label, width, (float) 0, 0x20ffffff, false, matrix, renderer, true, opacity, lightmapCoord );
|
font.renderString( label, width, (float) 0, 0x20ffffff, false, matrix, renderer, true, opacity, lightmapCoord );
|
||||||
|
@ -42,7 +42,7 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
stack.translate( 0, 0, 1 );
|
stack.translate( 0, 0, 1 );
|
||||||
|
|
||||||
identity = TransformationMatrix.identity();
|
identity = TransformationMatrix.identity();
|
||||||
flip = new TransformationMatrix( stack.getLast().getPositionMatrix() );
|
flip = new TransformationMatrix( stack.getLast().getMatrix() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TurtleModelCombination
|
private static class TurtleModelCombination
|
||||||
@ -97,15 +97,14 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
private final IBakedModel familyModel;
|
private final IBakedModel familyModel;
|
||||||
private final IBakedModel colourModel;
|
private final IBakedModel colourModel;
|
||||||
|
|
||||||
private HashMap<TurtleModelCombination, IBakedModel> m_cachedModels;
|
private final HashMap<TurtleModelCombination, IBakedModel> m_cachedModels = new HashMap<>();
|
||||||
private ItemOverrideList m_overrides;
|
private final ItemOverrideList m_overrides;
|
||||||
|
|
||||||
public TurtleSmartItemModel( IBakedModel familyModel, IBakedModel colourModel )
|
public TurtleSmartItemModel( IBakedModel familyModel, IBakedModel colourModel )
|
||||||
{
|
{
|
||||||
this.familyModel = familyModel;
|
this.familyModel = familyModel;
|
||||||
this.colourModel = colourModel;
|
this.colourModel = colourModel;
|
||||||
|
|
||||||
m_cachedModels = new HashMap<>();
|
|
||||||
m_overrides = new ItemOverrideList()
|
m_overrides = new ItemOverrideList()
|
||||||
{
|
{
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -1,260 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
package dan200.computercraft.client.render;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.client.FrameInfo;
|
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
|
||||||
import dan200.computercraft.shared.util.Colour;
|
|
||||||
import dan200.computercraft.shared.util.Palette;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.RenderSpecificHandEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*;
|
|
||||||
import static dan200.computercraft.client.gui.GuiComputer.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emulates map rendering for pocket computers.
|
|
||||||
*/
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
|
||||||
public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|
||||||
{
|
|
||||||
private static final int MARGIN = 2;
|
|
||||||
private static final int FRAME = 12;
|
|
||||||
private static final int LIGHT_HEIGHT = 8;
|
|
||||||
|
|
||||||
private static final ItemPocketRenderer INSTANCE = new ItemPocketRenderer();
|
|
||||||
|
|
||||||
private ItemPocketRenderer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void renderItem( RenderSpecificHandEvent event )
|
|
||||||
{
|
|
||||||
ItemStack stack = event.getItemStack();
|
|
||||||
if( !(stack.getItem() instanceof ItemPocketComputer) ) return;
|
|
||||||
|
|
||||||
event.setCanceled( true );
|
|
||||||
Minecraft minecraft = Minecraft.getInstance();
|
|
||||||
INSTANCE.renderItemFirstPerson(
|
|
||||||
event.getMatrixStack(), minecraft.func_228019_au_().func_228487_b_(),
|
|
||||||
minecraft.getRenderManager().func_229085_a_( minecraft.player, event.getPartialTicks() ),
|
|
||||||
event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack )
|
|
||||||
{
|
|
||||||
ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
|
|
||||||
Terminal terminal = computer == null ? null : computer.getTerminal();
|
|
||||||
|
|
||||||
int termWidth, termHeight;
|
|
||||||
if( terminal == null )
|
|
||||||
{
|
|
||||||
termWidth = ComputerCraft.terminalWidth_pocketComputer;
|
|
||||||
termHeight = ComputerCraft.terminalHeight_pocketComputer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
termWidth = terminal.getWidth();
|
|
||||||
termHeight = terminal.getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
int width = termWidth * FONT_WIDTH + MARGIN * 2;
|
|
||||||
int height = termHeight * FONT_HEIGHT + MARGIN * 2;
|
|
||||||
|
|
||||||
// Setup various transformations. Note that these are partially adapted from the corresponding method
|
|
||||||
// in ItemRenderer
|
|
||||||
transform.push();
|
|
||||||
// TODO: RenderSystem.disableLighting();
|
|
||||||
// TODO: RenderSystem.disableDepthTest();
|
|
||||||
|
|
||||||
RenderSystem.rotatef( 180f, 0f, 1f, 0f );
|
|
||||||
RenderSystem.rotatef( 180f, 0f, 0f, 1f );
|
|
||||||
transform.scale( 0.5f, 0.5f, 0.5f );
|
|
||||||
|
|
||||||
float scale = 0.75f / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT );
|
|
||||||
transform.scale( scale, scale, 0 );
|
|
||||||
transform.translate( -0.5 * width, -0.5 * height, 0 );
|
|
||||||
|
|
||||||
// Render the main frame
|
|
||||||
ItemPocketComputer item = (ItemPocketComputer) stack.getItem();
|
|
||||||
ComputerFamily family = item.getFamily();
|
|
||||||
int frameColour = item.getColour( stack );
|
|
||||||
renderFrame( family, frameColour, width, height );
|
|
||||||
|
|
||||||
// Render the light
|
|
||||||
int lightColour = ItemPocketComputer.getLightState( stack );
|
|
||||||
if( lightColour == -1 ) lightColour = Colour.Black.getHex();
|
|
||||||
renderLight( lightColour, width, height );
|
|
||||||
|
|
||||||
if( computer != null && terminal != null )
|
|
||||||
{
|
|
||||||
// If we've a computer and terminal then attempt to render it.
|
|
||||||
renderTerminal( terminal, !computer.isColour() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Otherwise render a plain background
|
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( BACKGROUND );
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
|
|
||||||
Colour black = Colour.Black;
|
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION );
|
|
||||||
renderTexture( buffer, 0, 0, 0, 0, width, height, black.getR(), black.getG(), black.getB() );
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: RenderSystem.enableDepthTest();
|
|
||||||
// TODO: RenderSystem.enableLighting();
|
|
||||||
transform.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderFrame( ComputerFamily family, int colour, int width, int height )
|
|
||||||
{
|
|
||||||
|
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( colour != -1
|
|
||||||
? BACKGROUND_COLOUR
|
|
||||||
: family == ComputerFamily.Normal ? BACKGROUND_NORMAL : BACKGROUND_ADVANCED
|
|
||||||
);
|
|
||||||
|
|
||||||
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
|
||||||
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
|
||||||
float b = (colour & 0xFF) / 255.0f;
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR );
|
|
||||||
|
|
||||||
// Top left, middle, right
|
|
||||||
renderTexture( buffer, -FRAME, -FRAME, 12, 28, FRAME, FRAME, r, g, b );
|
|
||||||
renderTexture( buffer, 0, -FRAME, 0, 0, width, FRAME, r, g, b );
|
|
||||||
renderTexture( buffer, width, -FRAME, 24, 28, FRAME, FRAME, r, g, b );
|
|
||||||
|
|
||||||
// Left and bright border
|
|
||||||
renderTexture( buffer, -FRAME, 0, 0, 28, FRAME, height, r, g, b );
|
|
||||||
renderTexture( buffer, width, 0, 36, 28, FRAME, height, r, g, b );
|
|
||||||
|
|
||||||
// Bottom left, middle, right. We do this in three portions: the top inner corners, an extended region for
|
|
||||||
// lights, and then the bottom outer corners.
|
|
||||||
renderTexture( buffer, -FRAME, height, 12, 40, FRAME, FRAME / 2, r, g, b );
|
|
||||||
renderTexture( buffer, 0, height, 0, 12, width, FRAME / 2, r, g, b );
|
|
||||||
renderTexture( buffer, width, height, 24, 40, FRAME, FRAME / 2, r, g, b );
|
|
||||||
|
|
||||||
renderTexture( buffer, -FRAME, height + FRAME / 2, 12, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
|
||||||
renderTexture( buffer, 0, height + FRAME / 2, 0, 16, width, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
|
||||||
renderTexture( buffer, width, height + FRAME / 2, 24, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
|
||||||
|
|
||||||
renderTexture( buffer, -FRAME, height + LIGHT_HEIGHT + FRAME / 2, 12, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b );
|
|
||||||
renderTexture( buffer, 0, height + LIGHT_HEIGHT + FRAME / 2, 0, 12 + FRAME / 2, width, FRAME / 2, r, g, b );
|
|
||||||
renderTexture( buffer, width, height + LIGHT_HEIGHT + FRAME / 2, 24, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b );
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderLight( int colour, int width, int height )
|
|
||||||
{
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.disableTexture();
|
|
||||||
|
|
||||||
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
|
||||||
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
|
||||||
float b = (colour & 0xFF) / 255.0f;
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR );
|
|
||||||
buffer.pos( width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
buffer.pos( width, height + LIGHT_HEIGHT + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
buffer.pos( width, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
buffer.pos( width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
RenderSystem.enableTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderTerminal( Terminal terminal, boolean greyscale )
|
|
||||||
{
|
|
||||||
synchronized( terminal )
|
|
||||||
{
|
|
||||||
int termWidth = terminal.getWidth();
|
|
||||||
int termHeight = terminal.getHeight();
|
|
||||||
|
|
||||||
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
|
||||||
Palette palette = terminal.getPalette();
|
|
||||||
|
|
||||||
// Render top/bottom borders
|
|
||||||
TextBuffer emptyLine = new TextBuffer( ' ', termWidth );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
emptyLine, MARGIN, 0,
|
|
||||||
terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
fontRenderer.drawString(
|
|
||||||
emptyLine, MARGIN, 2 * MARGIN + (termHeight - 1) * FixedWidthFontRenderer.FONT_HEIGHT,
|
|
||||||
terminal.getTextColourLine( termHeight - 1 ), terminal.getBackgroundColourLine( termHeight - 1 ), MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
|
|
||||||
// Render the actual text
|
|
||||||
for( int line = 0; line < termWidth; line++ )
|
|
||||||
{
|
|
||||||
TextBuffer text = terminal.getLine( line );
|
|
||||||
TextBuffer colour = terminal.getTextColourLine( line );
|
|
||||||
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
text, MARGIN, MARGIN + line * FONT_HEIGHT,
|
|
||||||
colour, backgroundColour, MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// And render the cursor;
|
|
||||||
int tx = terminal.getCursorX(), ty = terminal.getCursorY();
|
|
||||||
if( terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink() &&
|
|
||||||
tx >= 0 && ty >= 0 && tx < termWidth && ty < termHeight )
|
|
||||||
{
|
|
||||||
TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
new TextBuffer( '_', 1 ), MARGIN + FONT_WIDTH * tx, MARGIN + FONT_HEIGHT * ty,
|
|
||||||
cursorColour, null, 0, 0, greyscale, palette
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderTexture( IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, float r, float g, float b )
|
|
||||||
{
|
|
||||||
renderTexture( builder, x, y, textureX, textureY, width, height, width, height, r, g, b );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderTexture( IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, int textureWidth, int textureHeight, float r, float g, float b )
|
|
||||||
{
|
|
||||||
float scale = 1 / 255.0f;
|
|
||||||
builder.pos( x, y + height, 0 ).tex( textureX * scale, (textureY + textureHeight) * scale ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
builder.pos( x + width, y + height, 0 ).tex( (textureX + textureWidth) * scale, (textureY + textureHeight) * scale ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
builder.pos( x + width, y, 0 ).tex( (textureX + textureWidth) * scale, textureY * scale ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
builder.pos( x, y, 0 ).tex( textureX * scale, textureY * scale ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,10 @@ package dan200.computercraft.shared.util;
|
|||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gson.*;
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import net.minecraft.item.crafting.Ingredient;
|
import net.minecraft.item.crafting.Ingredient;
|
||||||
import net.minecraft.util.JSONUtils;
|
import net.minecraft.util.JSONUtils;
|
||||||
|
Loading…
Reference in New Issue
Block a user