Skip to content

Commit

Permalink
highlight interfaces from interface terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Feb 28, 2021
1 parent b4ba1af commit bc2e4c8
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/appeng/client/ClientHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Random;

import appeng.helpers.HighlighterHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.settings.KeyBinding;
Expand All @@ -37,6 +38,7 @@
import net.minecraft.world.World;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.ForgeModContainer;
Expand Down Expand Up @@ -106,6 +108,11 @@ public void init()
}
}

@SubscribeEvent
public void renderWorldLastEvent( RenderWorldLastEvent event) {
HighlighterHandler.tick(event);
}

@Override
public World getWorld()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
import java.io.IOException;
import java.util.*;

import akka.event.Logging;
import appeng.client.render.BlockPosHighlighter;
import appeng.util.BlockPosUtils;
import com.google.common.collect.HashMultimap;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
Expand All @@ -44,6 +50,12 @@
import appeng.util.Platform;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import org.lwjgl.util.Color;
import org.lwjgl.util.ReadableColor;

import static appeng.client.render.BlockPosHighlighter.hilightBlock;


public class GuiInterfaceTerminal extends AEBaseGui
Expand All @@ -57,6 +69,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
private final HashMap<Long, ClientDCInternalInv> byId = new HashMap<>();
private final HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
private final HashMap<ClientDCInternalInv,BlockPos> blockPosHashMap = new HashMap<>();
private final HashMap<GuiButton,ClientDCInternalInv> guiButtonHashMap = new HashMap<>();
private final ArrayList<String> names = new ArrayList<>();
private final ArrayList<Object> lines = new ArrayList<>();

Expand Down Expand Up @@ -100,11 +113,14 @@ public void initGui()
this.searchFieldOutputs.setTextColor( 0xFFFFFF );
this.searchFieldOutputs.setVisible( true );
this.searchFieldOutputs.setFocused( true );

}

@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.buttonList.clear();

this.fontRenderer.drawString( this.getGuiDisplayName( GuiText.InterfaceTerminal.getLocal() ), 8, 6, 4210752 );
this.fontRenderer.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );

Expand All @@ -130,6 +146,10 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
{
this.inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z, z * 18 + 8, 1 + offset ) );
}
GuiButton guiButton = new GuiButton( x, guiLeft + 1, guiTop + offset + 3, 8, 10, "?" );
guiButtonHashMap.put( guiButton , inv);
this.buttonList.add( guiButton );

}
else if( lineObj instanceof String )
{
Expand Down Expand Up @@ -173,10 +193,23 @@ protected void mouseClicked( final int xCoord, final int yCoord, final int btn )
super.mouseClicked( xCoord, yCoord, btn );
}

@Override
protected void actionPerformed( final GuiButton btn ) throws IOException
{
if( guiButtonHashMap.containsKey( btn ) )
{
BlockPos blockPos = blockPosHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
BlockPos blockPos2 = mc.player.getPosition();
hilightBlock( blockPos, System.currentTimeMillis() + 500 * BlockPosUtils.getDistance(blockPos, blockPos2) );
mc.player.sendStatusMessage( new TextComponentString( "The interface is now highlighted at " + "X: " + blockPos.getX() + "Y: " + blockPos.getY() + "Z: " + blockPos.getZ() ), false );
mc.player.closeScreen();
}
}

@Override
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.bindTexture( "guis/interfaceterminal.png" );
this.bindTexture( "guis/newinterfaceterminal.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );

int offset = 32;
Expand Down Expand Up @@ -286,6 +319,7 @@ public void postUpdate( final NBTTagCompound in )
private void refreshList()
{
this.byName.clear();
this.buttonList.clear();

final String searchFieldInputs = this.searchFieldInputs.getText().toLowerCase();
final String searchFieldOutputs = this.searchFieldOutputs.getText().toLowerCase();
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/appeng/client/render/BlockPosHighlighter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package appeng.client.render;

import net.minecraft.util.math.BlockPos;

// taken from McJty's McJtyLib
public class BlockPosHighlighter
{
private static BlockPos hilightedBlock;
private static long expireHilight;

public static void hilightBlock( BlockPos c, long expireHilight ) {
hilightedBlock = c;
BlockPosHighlighter.expireHilight = expireHilight;
}

public static BlockPos getHilightedBlock() {
return hilightedBlock;
}

public static long getExpireHilight() {
return expireHilight;
}


}
96 changes: 96 additions & 0 deletions src/main/java/appeng/helpers/HighlighterHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package appeng.helpers;

import appeng.client.render.BlockPosHighlighter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
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.util.math.BlockPos;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.lwjgl.opengl.GL11;

// taken from McJty's McJtyLib

public class HighlighterHandler
{

public static void tick( RenderWorldLastEvent event ) {
renderHilightedBlock(event);
}

private static void renderHilightedBlock( RenderWorldLastEvent event ) {
BlockPos c = BlockPosHighlighter.getHilightedBlock();
if (c == null) {
return;
}
Minecraft mc = Minecraft.getMinecraft();
long time = System.currentTimeMillis();

if (time > BlockPosHighlighter.getExpireHilight()) {
BlockPosHighlighter.hilightBlock(null, -1);
return;
}

if (((time / 500) & 1) == 0) {
return;
}

EntityPlayerSP p = mc.player;
double doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * event.getPartialTicks();
double doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * event.getPartialTicks();
double doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * event.getPartialTicks();

GlStateManager.pushMatrix();
GlStateManager.color(1.0f, 0, 0);
GlStateManager.glLineWidth(3);
GlStateManager.translate(-doubleX, -doubleY, -doubleZ);

GlStateManager.disableDepth();
GlStateManager.disableTexture2D();

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
float mx = c.getX();
float my = c.getY();
float mz = c.getZ();
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
renderHighLightedBlocksOutline(buffer, mx, my, mz, 1.0f, 0.0f, 0.0f, 1.0f);

tessellator.draw();

GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
}

public static void renderHighLightedBlocksOutline(BufferBuilder buffer, float mx, float my, float mz, float r, float g, float b, float a) {
buffer.pos(mx, my, mz).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my, mz).color(r, g, b, a).endVertex();
buffer.pos(mx, my, mz).color(r, g, b, a).endVertex();
buffer.pos(mx, my + 1, mz).color(r, g, b, a).endVertex();
buffer.pos(mx, my, mz).color(r, g, b, a).endVertex();
buffer.pos(mx, my, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my + 1, mz).color(r, g, b, a).endVertex();

buffer.pos(mx, my + 1, mz).color(r, g, b, a).endVertex();
buffer.pos(mx, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx, my + 1, mz).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my + 1, mz).color(r, g, b, a).endVertex();

buffer.pos(mx + 1, my, mz).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my, mz).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my + 1, mz).color(r, g, b, a).endVertex();

buffer.pos(mx, my, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx + 1, my, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx, my, mz + 1).color(r, g, b, a).endVertex();
buffer.pos(mx, my + 1, mz + 1).color(r, g, b, a).endVertex();
}
}
41 changes: 41 additions & 0 deletions src/main/java/appeng/util/BlockPosUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package appeng.util;

import net.minecraft.util.math.BlockPos;


public class BlockPosUtils
{
public static long getDistance( BlockPos blockPos, BlockPos blockPos2 )
{
int x;
if( (blockPos.getX() > 0 && blockPos2.getX() > 0) || (blockPos.getX() < 0 && blockPos2.getX() < 0))
{
x = blockPos.getX() - blockPos2.getX();
}
else
{
x = blockPos.getX() + blockPos2.getX();
}

int y;
if( (blockPos.getY() > 0 && blockPos2.getY() > 0) || (blockPos.getY() < 0 && blockPos2.getY() < 0) )
{
y = blockPos.getY() - blockPos2.getY();
}
else
{
y = blockPos.getY() + blockPos2.getY();
}

int z;
if( (blockPos.getZ() > 0 && blockPos2.getZ() > 0) || (blockPos.getZ() < 0 && blockPos2.getZ() < 0) )
{
z = blockPos.getZ() - blockPos2.getZ();
}
else
{
z = blockPos.getZ() + blockPos2.getZ();
}
return Math.abs( x ) + Math.abs( y ) + Math.abs( z );
}
}
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bc2e4c8

Please sign in to comment.