Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide P2P outputs from interface terminal #610

Merged
merged 10 commits into from
Nov 17, 2024
8 changes: 8 additions & 0 deletions src/main/java/appeng/api/util/WorldCoord.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package appeng.api.util;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

Expand Down Expand Up @@ -123,6 +124,13 @@ public static long getTaxicabDistance(WorldCoord blockPos, WorldCoord blockPos2)
return dx + dy + dz;
}

public static int getTaxicabDistance(WorldCoord blockPos, EntityPlayer player) {
int dx = Math.abs(blockPos.x - (int) player.posX);
int dy = Math.abs(blockPos.y - (int) player.posY);
int dz = Math.abs(blockPos.z - (int) player.posZ);
return dx + dy + dz;
}

public boolean isEqual(final WorldCoord c) {
return this.x == c.x && this.y == c.y && this.z == c.z;
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/appeng/client/ClientHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import net.minecraftforge.client.MinecraftForgeClient;
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.common.MinecraftForge;

Expand All @@ -46,6 +45,7 @@
import appeng.api.util.AEColor;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.BlockPosHighlighter;
import appeng.client.render.TESRWrapper;
import appeng.client.render.WorldRender;
import appeng.client.render.effects.AssemblerFX;
Expand All @@ -67,7 +67,6 @@
import appeng.entity.EntityTinyTNTPrimed;
import appeng.entity.RenderFloatingItem;
import appeng.entity.RenderTinyTNTPrimed;
import appeng.helpers.HighlighterHandler;
import appeng.helpers.IMouseWheelItem;
import appeng.hooks.TickHandler;
import appeng.hooks.TickHandler.PlayerColor;
Expand Down Expand Up @@ -103,6 +102,7 @@ public void postPlayerRender(final RenderLivingEvent.Pre p) {
@Override
public void init() {
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new BlockPosHighlighter());

for (ActionKey key : ActionKey.values()) {
final KeyBinding binding = new KeyBinding(key.getTranslationKey(), key.getDefaultKey(), KEY_CATEGORY);
Expand All @@ -111,11 +111,6 @@ public void init() {
}
}

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

@Override
public World getWorld() {
if (Platform.isClient()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentTranslation;

import org.apache.commons.lang3.time.DurationFormatUtils;
import org.lwjgl.opengl.GL11;
Expand All @@ -36,7 +35,6 @@
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.WorldCoord;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.IGuiTooltipHandler;
import appeng.client.gui.widgets.GuiScrollbar;
Expand Down Expand Up @@ -203,23 +201,13 @@ protected void actionPerformed(final GuiButton btn) {
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
if (this.hoveredNbtStack != null && isShiftKeyDown()) {
NBTTagCompound data = Platform.openNbtData(this.hoveredNbtStack);
WorldCoord blockPos2 = new WorldCoord(
(int) mc.thePlayer.posX,
(int) mc.thePlayer.posY,
(int) mc.thePlayer.posZ);
BlockPosHighlighter.clear();
for (DimensionalCoord blockPos : DimensionalCoord.readAsListFromNBT(data)) {
BlockPosHighlighter.highlightBlock(
blockPos,
System.currentTimeMillis() + 500 * WorldCoord.getTaxicabDistance(blockPos, blockPos2),
false);
mc.thePlayer.addChatMessage(
new ChatComponentTranslation(
PlayerMessages.InterfaceHighlighted.getName(),
blockPos.x,
blockPos.y,
blockPos.z));
}
// when using the highlight feature in the crafting GUI we want to show all the interfaces
// that currently received items so the player can see if the items are processed properly
BlockPosHighlighter.highlightBlocks(
mc.thePlayer,
DimensionalCoord.readAsListFromNBT(data),
PlayerMessages.InterfaceHighlighted.getName(),
PlayerMessages.InterfaceInOtherDim.getName());
mc.thePlayer.closeScreen();
}
super.mouseClicked(xCoord, yCoord, btn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -31,7 +32,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
Expand All @@ -49,7 +49,6 @@
import appeng.api.config.TerminalStyle;
import appeng.api.config.YesNo;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.WorldCoord;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.IGuiTooltipHandler;
import appeng.client.gui.IInterfaceTerminalPostUpdate;
Expand Down Expand Up @@ -858,7 +857,8 @@ private void parsePacketCmd(PacketInterfaceTerminalUpdate.PacketEntry cmd) {
addCmd.name,
addCmd.rows,
addCmd.rowSize,
addCmd.online).setLocation(addCmd.x, addCmd.y, addCmd.z, addCmd.dim)
addCmd.online,
addCmd.p2pOutput).setLocation(addCmd.x, addCmd.y, addCmd.z, addCmd.dim)
.setIcons(addCmd.selfRep, addCmd.dispRep).setItems(addCmd.items);
masterList.addEntry(entry);
} else if (cmd instanceof PacketInterfaceTerminalUpdate.PacketRemove) {
Expand Down Expand Up @@ -1173,7 +1173,7 @@ public void refreshVisible() {
String output = GuiInterfaceTerminal.this.searchFieldOutputs.getText().toLowerCase();

for (InterfaceTerminalEntry entry : entries) {
if (!entry.online) continue;
if (!entry.online || entry.p2pOutput) continue;

var moleAss = AEApi.instance().definitions().blocks().molecularAssembler().maybeStack(1);
entry.dispY = -9999;
Expand Down Expand Up @@ -1263,13 +1263,14 @@ private class InterfaceTerminalEntry {
int guiHeight;
int dispY = -9999;
boolean online;
boolean p2pOutput;
private Boolean[] brokenRecipes;
int numItems = 0;
/** Should recipe be filtered out/grayed out? */
boolean[] filteredRecipes;
private int hoveredSlotIdx = -1;

InterfaceTerminalEntry(long id, String name, int rows, int rowSize, boolean online) {
InterfaceTerminalEntry(long id, String name, int rows, int rowSize, boolean online, boolean p2pOutput) {
this.id = id;
if (StatCollector.canTranslate(name)) {
this.dispName = StatCollector.translateToLocal(name);
Expand All @@ -1285,6 +1286,7 @@ private class InterfaceTerminalEntry {
this.rows = rows;
this.rowSize = rowSize;
this.online = online;
this.p2pOutput = p2pOutput;
this.optionsButton = new GuiImgButton(2, 0, Settings.ACTIONS, ActionItems.HIGHLIGHT_INTERFACE);
this.optionsButton.setHalfSize(true);
this.guiHeight = 18 * rows + 1;
Expand Down Expand Up @@ -1389,26 +1391,13 @@ public boolean mouseClicked(int mouseX, int mouseY, int btn) {
&& mouseY > Math.max(optionsButton.yPosition, InterfaceSection.TITLE_HEIGHT)
&& mouseY <= Math.min(optionsButton.yPosition + optionsButton.height, viewHeight)) {
optionsButton.func_146113_a(mc.getSoundHandler());
DimensionalCoord blockPos = new DimensionalCoord(x, y, z, dim);
/* View in world */
WorldCoord blockPos2 = new WorldCoord(
(int) mc.thePlayer.posX,
(int) mc.thePlayer.posY,
(int) mc.thePlayer.posZ);
if (mc.theWorld.provider.dimensionId != dim) {
mc.thePlayer.addChatMessage(
new ChatComponentTranslation(PlayerMessages.InterfaceInOtherDim.getName(), dim));
} else {
BlockPosHighlighter.highlightBlock(
blockPos,
System.currentTimeMillis() + 500 * WorldCoord.getTaxicabDistance(blockPos, blockPos2));
mc.thePlayer.addChatMessage(
new ChatComponentTranslation(
PlayerMessages.InterfaceHighlighted.getName(),
blockPos.x,
blockPos.y,
blockPos.z));
}
// When using the highlight from the interface terminal, we want it to only
// highlight the interface containing the patterns and not any output p2p interfaces
BlockPosHighlighter.highlightBlocks(
mc.thePlayer,
Collections.singletonList(new DimensionalCoord(x, y, z, dim)),
PlayerMessages.InterfaceHighlighted.getName(),
PlayerMessages.InterfaceInOtherDim.getName());
mc.thePlayer.closeScreen();
return true;
}
Expand Down
137 changes: 110 additions & 27 deletions src/main/java/appeng/client/render/BlockPosHighlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,131 @@
import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.MathHelper;
import net.minecraftforge.client.event.RenderWorldLastEvent;

import org.lwjgl.opengl.GL11;

import appeng.api.util.DimensionalCoord;
import appeng.api.util.WorldCoord;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

// taken from McJty's McJtyLib
public class BlockPosHighlighter {

private static final List<DimensionalCoord> highlightedBlocks = new ArrayList<>();
private static long expireHighlight;
private static final int min = 3000;
private static final int max = min * 10;
private static long expireHighlightTime;
private static final int MIN_TIME = 3000;
private static final int MAX_TIME = MIN_TIME * 10;

public static void highlightBlock(DimensionalCoord c, long expireHighlight) {
highlightBlock(c, expireHighlight, true);
public static void highlightBlocks(EntityPlayer player, List<DimensionalCoord> interfaces, String foundMsg,
String wrongDimMsg) {
clear();
int highlightDuration = MIN_TIME;
for (DimensionalCoord coord : interfaces) {
if (player.worldObj.provider.dimensionId == coord.getDimension()) {
if (foundMsg != null) {
player.addChatMessage(new ChatComponentTranslation(foundMsg, coord.x, coord.y, coord.z));
}
} else {
if (wrongDimMsg != null) {
player.addChatMessage(new ChatComponentTranslation(wrongDimMsg, coord.getDimension()));
}
}
highlightedBlocks.add(coord);
highlightDuration = Math.max(
highlightDuration,
MathHelper.clamp_int(500 * WorldCoord.getTaxicabDistance(coord, player), MIN_TIME, MAX_TIME));
}
expireHighlightTime = System.currentTimeMillis() + highlightDuration;
}

public static void highlightBlock(DimensionalCoord c, long expireHighlight, boolean clear) {
if (clear) clear();
highlightedBlocks.add(c);
BlockPosHighlighter.expireHighlight = Math.max(
BlockPosHighlighter.expireHighlight,
Math.min(
System.currentTimeMillis() + max,
Math.max(expireHighlight, System.currentTimeMillis() + min)));
private static void clear() {
highlightedBlocks.clear();
expireHighlightTime = -1;
}

public static List<DimensionalCoord> getHighlightedBlocks() {
return highlightedBlocks;
}
@SubscribeEvent
public void renderHighlightedBlocks(RenderWorldLastEvent event) {
if (highlightedBlocks.isEmpty()) {
return;
}
long time = System.currentTimeMillis();
if (time > expireHighlightTime) {
clear();
return;
}
if (((time / 500) & 1) == 0) {
// this does the blinking effect
return;
}
Minecraft mc = Minecraft.getMinecraft();
int dimension = mc.theWorld.provider.dimensionId;

public static DimensionalCoord getHighlightedBlock() {
return highlightedBlocks.isEmpty() ? null : highlightedBlocks.get(0);
}
EntityPlayerSP p = mc.thePlayer;
double doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * event.partialTicks;
double doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * event.partialTicks;
double doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * event.partialTicks;

public static void clear() {
highlightedBlocks.clear();
expireHighlight = -1;
}
for (DimensionalCoord c : highlightedBlocks) {
if (dimension != c.getDimension()) {
continue;
}
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glLineWidth(3);
GL11.glTranslated(-doubleX, -doubleY, -doubleZ);

public static void remove(DimensionalCoord c) {
highlightedBlocks.remove(c);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);

renderHighLightedBlocksOutline(c.x, c.y, c.z);

GL11.glPopAttrib();
GL11.glPopMatrix();
}
}

public static long getExpireHighlight() {
return expireHighlight;
private static void renderHighLightedBlocksOutline(double x, double y, double z) {
Tessellator tess = Tessellator.instance;
tess.startDrawing(GL11.GL_LINE_STRIP);

tess.setColorRGBA_F(1.0f, 0.0f, 0.0f, 1.0f);

tess.addVertex(x, y, z);
tess.addVertex(x, y + 1, z);
tess.addVertex(x, y + 1, z + 1);
tess.addVertex(x, y, z + 1);
tess.addVertex(x, y, z);

tess.addVertex(x + 1, y, z);
tess.addVertex(x + 1, y + 1, z);
tess.addVertex(x + 1, y + 1, z + 1);
tess.addVertex(x + 1, y, z + 1);
tess.addVertex(x + 1, y, z);

tess.addVertex(x, y, z);
tess.addVertex(x + 1, y, z);
tess.addVertex(x + 1, y, z + 1);
tess.addVertex(x, y, z + 1);
tess.addVertex(x, y + 1, z + 1);
tess.addVertex(x + 1, y + 1, z + 1);
tess.addVertex(x + 1, y + 1, z);
tess.addVertex(x + 1, y, z);
tess.addVertex(x, y, z);
tess.addVertex(x + 1, y, z);
tess.addVertex(x + 1, y + 1, z);
tess.addVertex(x, y + 1, z);
tess.addVertex(x, y + 1, z + 1);
tess.addVertex(x + 1, y + 1, z + 1);
tess.addVertex(x + 1, y, z + 1);
tess.addVertex(x, y, z + 1);

tess.draw();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import appeng.helpers.InventoryAction;
import appeng.items.misc.ItemEncodedPattern;
import appeng.parts.AEBasePart;
import appeng.parts.p2p.PartP2PTunnel;
import appeng.parts.reporting.PartInterfaceTerminal;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
Expand Down Expand Up @@ -311,7 +312,8 @@ private PacketInterfaceTerminalUpdate updateList() {
update.addNewEntry(entry.id, entry.name, entry.online)
.setLoc(entry.x, entry.y, entry.z, entry.dim, entry.side.ordinal())
.setItems(entry.rows, entry.rowSize, entry.invNbt)
.setReps(machine.getSelfRep(), machine.getDisplayRep());
.setReps(machine.getSelfRep(), machine.getDisplayRep())
.setP2POutput(machine instanceof PartP2PTunnel<?>p2pTunnel && p2pTunnel.isOutput());
tracked.put(machine, entry);
trackedById.put(entry.id, entry);
visited.add(machine);
Expand Down
Loading