use of gregtech.api.pattern.BlockWorldState in project GregTech by GregTechCEu.
the class MultiblockInfoRecipeWrapper method drawInfo.
@Override
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
WorldSceneRenderer renderer = getCurrentRenderer();
int sceneHeight = recipeHeight - PARTS_HEIGHT;
renderer.render(recipeLayout.getPosX(), recipeLayout.getPosY(), recipeWidth, sceneHeight, mouseX + recipeLayout.getPosX(), mouseY + recipeLayout.getPosY());
drawMultiblockName(recipeWidth);
// reset colors (so any elements render after this point are not dark)
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
int iconX = recipeWidth - (ICON_SIZE + RIGHT_PADDING);
int iconY = 49;
this.infoIcon.draw(minecraft, iconX, iconY);
this.drawInfoIcon = iconX <= mouseX && mouseX <= iconX + ICON_SIZE && iconY <= mouseY && mouseY <= iconY + ICON_SIZE;
// draw parts slots
for (int i = 0; i < MAX_PARTS; ++i) {
this.slot.draw(minecraft, SLOT_SIZE * i - (SLOTS_PER_ROW * SLOT_SIZE) * (i / SLOTS_PER_ROW) + (SLOT_SIZE / 2) - 2, sceneHeight + SLOT_SIZE * (i / SLOTS_PER_ROW));
}
// draw candidates slots
for (int i = 0; i < predicates.size(); i++) {
this.slot.draw(minecraft, 5 + (i / 6) * SLOT_SIZE, (i % 6) * SLOT_SIZE + 10);
}
// draw buttons
for (GuiButton button : buttons.keySet()) {
button.drawButton(minecraft, mouseX, mouseY, 0.0f);
}
tooltipBlockStack = null;
this.predicateTips = 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;
rotationPitch = rotationPitch % 360;
rotationYaw = (float) MathHelper.clamp(rotationYaw + (mouseY - lastMouseY), -89.9, 89.9);
} 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, 999);
}
}
renderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
}
if (!(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);
TraceabilityPredicate predicates = patterns[currentRendererPage].predicateMap.get(rayTraceResult.getBlockPos());
if (predicates != null) {
BlockWorldState worldState = new BlockWorldState();
worldState.update(renderer.world, rayTraceResult.getBlockPos(), new PatternMatchContext(), new HashMap<>(), new HashMap<>(), predicates);
for (TraceabilityPredicate.SimplePredicate common : predicates.common) {
if (common.test(worldState)) {
predicateTips = common.getToolTips(predicates);
break;
}
}
if (predicateTips == null) {
for (TraceabilityPredicate.SimplePredicate limit : predicates.limited) {
if (limit.test(worldState)) {
predicateTips = limit.getToolTips(predicates);
break;
}
}
}
}
if (!itemStack.isEmpty()) {
tooltipBlockStack = itemStack;
}
}
lastRender = System.currentTimeMillis();
this.lastMouseX = mouseX;
this.lastMouseY = mouseY;
GlStateManager.disableRescaleNormal();
GlStateManager.disableLighting();
RenderHelper.disableStandardItemLighting();
}
Aggregations