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

JEI Preview Fixes #169

Merged
merged 6 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package gregtech.api.gui.resources;

import gregtech.api.gui.widgets.SlotWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL14;

public class ItemStackTexture implements IGuiTexture{
private final ItemStack[] itemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void init() {
.device(DeviceHardware.DEVICE.WIRELESS)
.build();
AppRegistryBuilder.create(new BatteryManagerApp()).defaultApp()
.battery(GTValues.ULV, 10)
.battery(GTValues.ULV, 0)
.build();
AppRegistryBuilder.create(new HardwareManagerApp()).defaultApp().build();
AppRegistryBuilder.create(new AppStoreApp()).defaultApp().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;

import java.util.Arrays;
import java.util.Collections;

public class HardwareSlotWidget extends WidgetGroup {
Expand Down Expand Up @@ -77,9 +78,9 @@ public void drawInForeground(int mouseX, int mouseY) {
} else {
String info = hardware.addInformation();
if (info == null) {
drawHoveringText(null, Collections.singletonList(hardware.getLocalizedName()), 300, mouseX, mouseY);
drawHoveringText(null, Arrays.asList(hardware.getLocalizedName(), I18n.format("terminal.hardware.tip.remove")), 300, mouseX, mouseY);
} else {
drawHoveringText(null, Collections.singletonList(String.format("%s (%s)", hardware.getLocalizedName(), info)), 300, mouseX, mouseY);
drawHoveringText(null, Arrays.asList(String.format("%s (%s)", hardware.getLocalizedName(), info), I18n.format("terminal.hardware.tip.remove")), 300, mouseX, mouseY);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public float getDefaultZoom() {
}

public List<String> informationText() {

return Stream.of("gregtech.multiblock.preview.tilt", "gregtech.multiblock.preview.zoom",
"gregtech.multiblock.preview.pan", "gregtech.multiblock.preview.move", "gregtech.multiblock.preview.reset")
return Stream.of("gregtech.multiblock.preview.zoom", "gregtech.multiblock.preview.rotate")
.map(I18n::format)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
Expand All @@ -44,7 +45,6 @@
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.client.model.pipeline.LightUtil;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -89,7 +89,6 @@ public MBPattern(final WorldSceneRenderer sceneRenderer, final List<ItemStack> p
private Vector3f center;
private float rotationYaw;
private float rotationPitch;
private float maxZoom;
private float zoom;

private GuiButton buttonPreviousPattern;
Expand Down Expand Up @@ -122,6 +121,8 @@ public MultiblockInfoPage getInfoPage() {
return infoPage;
}

private static MultiblockInfoRecipeWrapper lastWrapper;

public void setRecipeLayout(RecipeLayout layout, IGuiHelper guiHelper) {
this.recipeLayout = layout;

Expand All @@ -130,29 +131,29 @@ public void setRecipeLayout(RecipeLayout layout, IGuiHelper guiHelper) {

IDrawable border = layout.getRecipeCategory().getBackground();
preparePlaceForParts(border.getHeight());
this.buttons.clear();
this.nextLayerButton = new GuiButton(0, border.getWidth() - (ICON_SIZE + RIGHT_PADDING), 70, ICON_SIZE, ICON_SIZE, "");
this.buttonPreviousPattern = new GuiButton(0, border.getWidth() - ((2 * ICON_SIZE) + RIGHT_PADDING + 1), 90, ICON_SIZE, ICON_SIZE, "<");
this.buttonNextPattern = new GuiButton(0, border.getWidth() - (ICON_SIZE + RIGHT_PADDING), 90, ICON_SIZE, ICON_SIZE, ">");
this.buttons.put(nextLayerButton, this::toggleNextLayer);
this.buttons.put(buttonPreviousPattern, () -> switchRenderPage(-1));
this.buttons.put(buttonNextPattern, () -> switchRenderPage(1));

boolean isPagesDisabled = patterns.length == 1;
this.buttonPreviousPattern.visible = !isPagesDisabled;
this.buttonNextPattern.visible = !isPagesDisabled;
this.buttonPreviousPattern.enabled = false;
this.buttonNextPattern.enabled = patterns.length > 1;

if (Mouse.getEventDWheel() == 0) {
this.maxZoom = infoPage.getDefaultZoom() * 15;
this.zoom = this.maxZoom;
if (Mouse.getEventDWheel() == 0 || lastWrapper != this) {
lastWrapper = this;
this.buttons.clear();
this.nextLayerButton = new GuiButton(0, border.getWidth() - (ICON_SIZE + RIGHT_PADDING), 70, ICON_SIZE, ICON_SIZE, "");
this.buttonPreviousPattern = new GuiButton(0, border.getWidth() - ((2 * ICON_SIZE) + RIGHT_PADDING + 1), 90, ICON_SIZE, ICON_SIZE, "<");
this.buttonNextPattern = new GuiButton(0, border.getWidth() - (ICON_SIZE + RIGHT_PADDING), 90, ICON_SIZE, ICON_SIZE, ">");
this.buttons.put(nextLayerButton, this::toggleNextLayer);
this.buttons.put(buttonPreviousPattern, () -> switchRenderPage(-1));
this.buttons.put(buttonNextPattern, () -> switchRenderPage(1));

boolean isPagesDisabled = patterns.length == 1;
this.buttonPreviousPattern.visible = !isPagesDisabled;
this.buttonNextPattern.visible = !isPagesDisabled;
this.buttonPreviousPattern.enabled = false;
this.buttonNextPattern.enabled = patterns.length > 1;

this.zoom = infoPage.getDefaultZoom() * 15;
this.rotationYaw = 20.0f;
this.rotationPitch = 135.0f;
this.currentRendererPage = 0;
setNextLayer(-1);
} else {
zoom = (float) MathHelper.clamp(zoom + (Mouse.getEventDWheel() < 0 ? 0.5 : -0.5), 3, maxZoom);
zoom = (float) MathHelper.clamp(zoom + (Mouse.getEventDWheel() < 0 ? 0.5 : -0.5), 3, 999);
setNextLayer(getLayerIndex());
}
if (center != null) {
Expand Down Expand Up @@ -205,7 +206,9 @@ private void switchRenderPage(int amount) {
this.currentRendererPage = newIndex;
this.buttonNextPattern.enabled = newIndex < maxIndex;
this.buttonPreviousPattern.enabled = newIndex > 0;
setNextLayer(-1);
updateParts();
getCurrentRenderer().setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
}
}

Expand Down Expand Up @@ -249,14 +252,20 @@ public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHe
button.drawButton(minecraft, mouseX, mouseY, 0.0f);
}

drawHoveringInformationText(minecraft, infoPage.informationText(), mouseX, mouseY);

this.tooltipBlockStack = null;
RayTraceResult rayTraceResult = renderer.getLastTraceResult();
boolean insideView = mouseX >= 0 && mouseY >= 0 &&
mouseX < recipeWidth && mouseY < sceneHeight;
boolean leftClickHeld = Mouse.isButtonDown(0);
boolean rightClickHeld = Mouse.isButtonDown(1);
if (insideView) {
for (GuiButton button : buttons.keySet()) {
if (button.isMouseOver()) {
insideView = false;
break;
}
}
}
if (insideView) {
if (leftClickHeld) {
rotationPitch += mouseX - lastMouseX + 360;
Expand All @@ -265,13 +274,13 @@ public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHe
} else if (rightClickHeld) {
int mouseDeltaY = mouseY - lastMouseY;
if (Math.abs(mouseDeltaY) > 1) {
this.zoom = (float) MathHelper.clamp(zoom + (mouseDeltaY > 0 ? 0.5 : -0.5), 3, maxZoom);
this.zoom = (float) MathHelper.clamp(zoom + (mouseDeltaY > 0 ? 0.5 : -0.5), 3, 999);
}
}
renderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
}

if (!(leftClickHeld || rightClickHeld) && rayTraceResult != null && !renderer.world.isAirBlock(rayTraceResult.getBlockPos())) {
if (!drawHoveringInformationText(minecraft, infoPage.informationText(), mouseX, mouseY) && !(leftClickHeld || rightClickHeld) && rayTraceResult != null && !renderer.world.isAirBlock(rayTraceResult.getBlockPos())) {
IBlockState blockState = renderer.world.getBlockState(rayTraceResult.getBlockPos());
ItemStack itemStack = blockState.getBlock().getPickBlock(blockState, rayTraceResult, renderer.world, rayTraceResult.getBlockPos(), minecraft.player);
if (itemStack != null && !itemStack.isEmpty()) {
Expand All @@ -281,18 +290,24 @@ public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHe

this.lastMouseX = mouseX;
this.lastMouseY = mouseY;

GlStateManager.disableRescaleNormal();
GlStateManager.disableLighting();
RenderHelper.disableStandardItemLighting();
}

@SideOnly(Side.CLIENT)
protected void drawHoveringInformationText(Minecraft minecraft, List<String> tooltip, int mouseX, int mouseY) {
protected boolean drawHoveringInformationText(Minecraft minecraft, List<String> tooltip, int mouseX, int mouseY) {
int minX = recipeLayout.getRecipeCategory().getBackground().getWidth();
int[] yRange = new int[]{49, 69};
int[] xRange = new int[]{minX - (ICON_SIZE + RIGHT_PADDING), minX - RIGHT_PADDING};
//Only draw the hovering information tooltip above the information icon
if (isMouseWithinRange(yRange, xRange, mouseY, mouseX)) {
GuiUtils.drawHoveringText(tooltip, mouseX, mouseY,
176, 176, -1, minecraft.fontRenderer);
return true;
}
return false;
}

private boolean isMouseWithinRange(int[] yRange, int[] xRange, int mouseY, int mouseX) {
Expand Down Expand Up @@ -451,6 +466,10 @@ private MBPattern initializePattern(MultiblockShapeInfo shapeInfo, Set<ItemStack
@SideOnly(Side.CLIENT)
private void renderBlockOverLay(RayTraceResult rayTraceResult) {
BlockPos pos = rayTraceResult.getBlockPos();
GlStateManager.disableDepth();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);

Tessellator tessellator = Tessellator.getInstance();
GlStateManager.disableTexture2D();
CCRenderState renderState = CCRenderState.instance();
Expand All @@ -460,14 +479,16 @@ private void renderBlockOverLay(RayTraceResult rayTraceResult) {
BlockRenderer.BlockFace blockFace = new BlockRenderer.BlockFace();
renderState.setModel(blockFace);
for (EnumFacing renderSide : EnumFacing.VALUES) {
float diffuse = LightUtil.diffuseLight(renderSide);
int color = (int) (255 * diffuse);
multiplier.colour = RenderUtil.packColor(color, color, color, 100);
multiplier.colour = RenderUtil.packColor(255, 0, 0, 255);
blockFace.loadCuboidFace(Cuboid6.full, renderSide.getIndex());
renderState.render();
}
renderState.draw();
GlStateManager.enableTexture2D();

GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.enableDepth();
}

}
10 changes: 4 additions & 6 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3849,11 +3849,8 @@ gregtech.multiblock.universal.distinct.no=No
gregtech.multiblock.universal.distinct.yes=Yes
gregtech.multiblock.universal.distinct.info=If enabled, each Item Input Bus will be treated as fully distinct from each other for recipe lookup. Useful for things like Programmed Circuits, Extruder Shapes, etc.

gregtech.multiblock.preview.tilt=Shift+LMB to tilt
gregtech.multiblock.preview.zoom=Shift+RMB to zoom
gregtech.multiblock.preview.pan=LMB+Drag to pan
gregtech.multiblock.preview.move=RMB+Drag to move
gregtech.multiblock.preview.reset=Scroll Mousewheel to reset
gregtech.multiblock.preview.zoom=Use mousewheel or right-click+Drag to zoom
gregtech.multiblock.preview.rotate=Click and drag to rotate
gregtech.multiblock.preview.any_hatch=Any tier hatch can be used to form the structure
gregtech.multiblock.preview.any_hatch_maintenance=Any type of maintenance hatch can be used to form the structure
gregtech.multiblock.preview.limit=Minimum Limit: %d
Expand Down Expand Up @@ -4064,6 +4061,7 @@ terminal.console.controllable=set working enable
terminal.hardware.description=Hardware Manager, masterpieces of elegance and precision. How can a tablet be without hardware?
terminal.hardware.select=Mounting hardware
terminal.hardware.remove=Remove hardware
terminal.hardware.tip.remove=§4right-click remove the hardware

terminal.battery.description=Battery manager, visually analyzing your app's energy consumption.

Expand All @@ -4073,7 +4071,7 @@ terminal.store.miss=Require %s (%d).

terminal.ar.open=Open AR

terminal.multiblock_ar.description=Remember the §cFree Wrench§r? Unfortunately, it it's gone. It doesn't matter, we have a new technology now. This app can also help you build your multi-block machine.
terminal.multiblock_ar.description=Remember the §cFreedom Wrench§r? Unfortunately, it it's gone. It doesn't matter, we have a new technology now. This app can also help you build your multi-block machine.
terminal.multiblock_ar.tier.0=AR Camera
terminal.multiblock_ar.tier.1=3D Builder
terminal.multiblock_ar.unlock=Unlock this mode after the upgrade
Expand Down