use of gregtech.api.render.scene.WorldSceneRenderer in project GregTech by GregTechCE.
the class MultiblockInfoRecipeWrapper method toggleNextLayer.
private void toggleNextLayer() {
WorldSceneRenderer renderer = getCurrentRenderer();
int height = (int) renderer.getSize().getY() - 1;
if (++this.layerIndex > height) {
// if current layer index is more than max height, reset it
// to display all layers
this.layerIndex = -1;
}
setNextLayer(layerIndex);
}
use of gregtech.api.render.scene.WorldSceneRenderer in project GregTech by GregTechCE.
the class MultiblockInfoRecipeWrapper method shouldDisplayBlock.
private boolean shouldDisplayBlock(BlockPos pos) {
if (getLayerIndex() == -1)
return true;
WorldSceneRenderer renderer = getCurrentRenderer();
int minHeight = (int) renderer.world.getMinPos().getY();
int relativeHeight = pos.getY() - minHeight;
return relativeHeight == getLayerIndex();
}
use of gregtech.api.render.scene.WorldSceneRenderer in project GregTech by GregTechCE.
the class MultiblockInfoRecipeWrapper method initializePattern.
private MBPattern initializePattern(MultiblockShapeInfo shapeInfo, Set<ItemStackKey> blockDrops) {
Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
BlockInfo[][][] blocks = shapeInfo.getBlocks();
for (int z = 0; z < blocks.length; z++) {
BlockInfo[][] aisle = blocks[z];
for (int y = 0; y < aisle.length; y++) {
BlockInfo[] column = aisle[y];
for (int x = 0; x < column.length; x++) {
BlockPos blockPos = new BlockPos(x, y, z);
BlockInfo blockInfo = column[x];
blockMap.put(blockPos, blockInfo);
}
}
}
WorldSceneRenderer worldSceneRenderer = new WorldSceneRenderer(blockMap);
worldSceneRenderer.world.updateEntities();
HashMap<ItemStackKey, PartInfo> partsMap = new HashMap<>();
gatherBlockDrops(worldSceneRenderer.world, blockMap, blockDrops, partsMap);
worldSceneRenderer.setRenderCallback(this);
worldSceneRenderer.setRenderFilter(this::shouldDisplayBlock);
ArrayList<PartInfo> partInfos = new ArrayList<>(partsMap.values());
partInfos.sort((one, two) -> {
if (one.isController)
return -1;
if (two.isController)
return +1;
if (one.isTile && !two.isTile)
return -1;
if (two.isTile && !one.isTile)
return +1;
if (one.blockId != two.blockId)
return two.blockId - one.blockId;
return two.amount - one.amount;
});
ArrayList<ItemStack> parts = new ArrayList<>();
for (PartInfo partInfo : partInfos) {
parts.add(partInfo.getItemStack());
}
return new MBPattern(worldSceneRenderer, parts);
}
use of gregtech.api.render.scene.WorldSceneRenderer in project GregTech by GregTechCE.
the class MultiblockInfoRecipeWrapper method drawInfo.
@Override
public void drawInfo(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, 0xC6C6C6);
drawMultiblockName(recipeWidth);
// reset colors (so any elements render after this point are not dark)
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.infoIcon.draw(minecraft, recipeWidth - (ICON_SIZE + RIGHT_PADDING), 49);
for (int i = 0; i < MAX_PARTS; ++i) {
this.slot.draw(minecraft, SLOT_SIZE * i - (SLOTS_PER_ROW * SLOT_SIZE) * (i / SLOTS_PER_ROW), sceneHeight + SLOT_SIZE * (i / SLOTS_PER_ROW));
}
// the button by mousing over it, leaks into other gui elements?
for (GuiButton button : buttons.keySet()) {
button.drawButton(minecraft, mouseX, mouseY, 0.0f);
}
drawHoveringInformationText(minecraft, infoPage.informationText(), mouseX, mouseY);
this.tooltipBlockStack = null;
BlockPos pos = renderer.getLastHitBlock();
boolean insideView = mouseX >= 0 && mouseY >= 0 && mouseX < recipeWidth && mouseY < sceneHeight;
boolean leftClickHeld = Mouse.isButtonDown(0);
boolean rightClickHeld = Mouse.isButtonDown(1);
boolean isHoldingShift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);
if (insideView) {
if (leftClickHeld) {
if (isHoldingShift) {
int mouseDeltaY = mouseY - lastMouseY;
this.rotationPitch += mouseDeltaY * 2.0f;
} else {
int mouseDeltaX = mouseX - lastMouseX;
this.rotationYaw += mouseDeltaX * 2.0f;
}
} else if (rightClickHeld) {
int mouseDeltaY = mouseY - lastMouseY;
if (isHoldingShift) {
this.zoom *= Math.pow(1.05d, -mouseDeltaY);
} else {
int mouseDeltaX = mouseX - lastMouseX;
this.panX -= mouseDeltaX / 2.0f;
this.panY -= mouseDeltaY / 2.0f;
}
}
}
if (!(leftClickHeld || rightClickHeld) && pos != null && !renderer.world.isAirBlock(pos)) {
IBlockState blockState = renderer.world.getBlockState(pos);
RayTraceResult result = new CuboidRayTraceResult(new Vector3(0.5, 0.5, 0.5).add(pos), pos, EnumFacing.UP, new IndexedCuboid6(null, Cuboid6.full), 1.0);
ItemStack itemStack = blockState.getBlock().getPickBlock(blockState, result, renderer.world, pos, minecraft.player);
if (itemStack != null && !itemStack.isEmpty()) {
this.tooltipBlockStack = itemStack;
}
}
this.lastMouseX = mouseX;
this.lastMouseY = mouseY;
}
Aggregations