use of gregtech.client.utils.TrackedDummyWorld in project GregTech by GregTechCEu.
the class MultiblockInfoRecipeWrapper method initializePattern.
private MBPattern initializePattern(MultiblockShapeInfo shapeInfo, Set<ItemStackKey> blockDrops) {
Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
MultiblockControllerBase controllerBase = null;
BlockInfo[][][] blocks = shapeInfo.getBlocks();
for (int x = 0; x < blocks.length; x++) {
BlockInfo[][] aisle = blocks[x];
for (int y = 0; y < aisle.length; y++) {
BlockInfo[] column = aisle[y];
for (int z = 0; z < column.length; z++) {
if (column[z].getTileEntity() instanceof MetaTileEntityHolder && ((MetaTileEntityHolder) column[z].getTileEntity()).getMetaTileEntity() instanceof MultiblockControllerBase) {
controllerBase = (MultiblockControllerBase) ((MetaTileEntityHolder) column[z].getTileEntity()).getMetaTileEntity();
}
blockMap.put(new BlockPos(x, y, z), column[z]);
}
}
}
TrackedDummyWorld world = new TrackedDummyWorld();
ImmediateWorldSceneRenderer worldSceneRenderer = new ImmediateWorldSceneRenderer(world);
worldSceneRenderer.setClearColor(0xC6C6C6);
world.addBlocks(blockMap);
Vector3f size = world.getSize();
Vector3f minPos = world.getMinPos();
center = new Vector3f(minPos.x + size.x / 2, minPos.y + size.y / 2, minPos.z + size.z / 2);
worldSceneRenderer.addRenderedBlocks(world.renderedBlocks, null);
worldSceneRenderer.setOnLookingAt(ray -> {
});
worldSceneRenderer.setAfterWorldRender(renderer -> {
BlockPos look = worldSceneRenderer.getLastTraceResult() == null ? null : worldSceneRenderer.getLastTraceResult().getBlockPos();
if (look != null && look.equals(selected)) {
renderBlockOverLay(selected, 200, 75, 75);
return;
}
renderBlockOverLay(look, 150, 150, 150);
renderBlockOverLay(selected, 255, 0, 0);
});
world.updateEntities();
world.setRenderFilter(pos -> worldSceneRenderer.renderedBlocksMap.keySet().stream().anyMatch(c -> c.contains(pos)));
List<ItemStack> parts = gatherBlockDrops(worldSceneRenderer.world, blockMap, blockDrops).values().stream().sorted((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;
}).map(PartInfo::getItemStack).collect(Collectors.toList());
Map<BlockPos, TraceabilityPredicate> predicateMap = new HashMap<>();
if (controllerBase != null) {
controllerBase.structurePattern.cache.forEach((pos, blockInfo) -> predicateMap.put(BlockPos.fromLong(pos), (TraceabilityPredicate) blockInfo.getInfo()));
}
return new MBPattern(worldSceneRenderer, parts, predicateMap);
}
use of gregtech.client.utils.TrackedDummyWorld in project GregTech by GregTechCEu.
the class MultiblockPreviewRenderer method renderControllerInList.
public static void renderControllerInList(MultiblockControllerBase controllerBase, MultiblockShapeInfo shapeInfo, int layer) {
BlockPos mbpPos = controllerBase.getPos();
EnumFacing frontFacing, previewFacing;
previewFacing = controllerBase.getFrontFacing();
BlockPos controllerPos = BlockPos.ORIGIN;
MultiblockControllerBase mte = null;
BlockInfo[][][] blocks = shapeInfo.getBlocks();
Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
int maxY = 0;
for (int x = 0; x < blocks.length; x++) {
BlockInfo[][] aisle = blocks[x];
maxY = Math.max(maxY, aisle.length);
for (int y = 0; y < aisle.length; y++) {
BlockInfo[] column = aisle[y];
for (int z = 0; z < column.length; z++) {
blockMap.put(new BlockPos(x, y, z), column[z]);
MetaTileEntity metaTE = column[z].getTileEntity() instanceof MetaTileEntityHolder ? ((MetaTileEntityHolder) column[z].getTileEntity()).getMetaTileEntity() : null;
if (metaTE instanceof MultiblockControllerBase && metaTE.metaTileEntityId.equals(controllerBase.metaTileEntityId)) {
controllerPos = new BlockPos(x, y, z);
previewFacing = metaTE.getFrontFacing();
mte = (MultiblockControllerBase) metaTE;
break;
}
}
}
}
TrackedDummyWorld world = new TrackedDummyWorld();
world.addBlocks(blockMap);
int finalMaxY = layer % (maxY + 1);
world.setRenderFilter(pos -> pos.getY() + 1 == finalMaxY || finalMaxY == 0);
EnumFacing facing = controllerBase.getFrontFacing();
EnumFacing spin = EnumFacing.NORTH;
// TODO SIDEWAYS ONE DAY
// spin = controllerBase.getSpin();
frontFacing = facing.getYOffset() == 0 ? facing : facing.getYOffset() < 0 ? spin : spin.getOpposite();
Rotation rotatePreviewBy = Rotation.values()[(4 + frontFacing.getHorizontalIndex() - previewFacing.getHorizontalIndex()) % 4];
Minecraft mc = Minecraft.getMinecraft();
BlockRendererDispatcher brd = mc.getBlockRendererDispatcher();
Tessellator tes = Tessellator.getInstance();
BufferBuilder buff = tes.getBuffer();
GlStateManager.pushMatrix();
GlStateManager.translate(mbpPos.getX(), mbpPos.getY(), mbpPos.getZ());
GlStateManager.translate(0.5, 0, 0.5);
GlStateManager.rotate(rotatePreviewBy.ordinal() * 90, 0, -1, 0);
GlStateManager.translate(-0.5, 0, -0.5);
if (facing == EnumFacing.UP) {
GlStateManager.translate(0.5, 0.5, 0.5);
GlStateManager.rotate(90, -previewFacing.getZOffset(), 0, previewFacing.getXOffset());
GlStateManager.translate(-0.5, -0.5, -0.5);
} else if (facing == EnumFacing.DOWN) {
GlStateManager.translate(0.5, 0.5, 0.5);
GlStateManager.rotate(90, previewFacing.getZOffset(), 0, -previewFacing.getXOffset());
GlStateManager.translate(-0.5, -0.5, -0.5);
} else {
int degree = 90 * (spin == EnumFacing.EAST ? -1 : spin == EnumFacing.SOUTH ? 2 : spin == EnumFacing.WEST ? 1 : 0);
GlStateManager.translate(0.5, 0.5, 0.5);
GlStateManager.rotate(degree, previewFacing.getXOffset(), 0, previewFacing.getZOffset());
GlStateManager.translate(-0.5, -0.5, -0.5);
}
if (mte != null) {
mte.checkStructurePattern();
}
TargetBlockAccess targetBA = new TargetBlockAccess(world, BlockPos.ORIGIN);
for (BlockPos pos : blockMap.keySet()) {
targetBA.setPos(pos);
GlStateManager.pushMatrix();
BlockPos.MutableBlockPos tPos = new BlockPos.MutableBlockPos(pos.subtract(controllerPos));
GlStateManager.translate(tPos.getX(), tPos.getY(), tPos.getZ());
GlStateManager.translate(0.125, 0.125, 0.125);
GlStateManager.scale(0.75, 0.75, 0.75);
buff.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
IBlockState state = world.getBlockState(pos);
for (BlockRenderLayer brl : BlockRenderLayer.values()) {
if (state.getBlock().canRenderInLayer(state, brl)) {
ForgeHooksClient.setRenderLayer(brl);
brd.renderBlock(state, BlockPos.ORIGIN, targetBA, buff);
}
}
tes.draw();
GlStateManager.popMatrix();
}
GlStateManager.popMatrix();
}
use of gregtech.client.utils.TrackedDummyWorld in project GregTech by GregTechCEu.
the class AdvancedMonitorPluginBehavior method createWorldScene.
@SideOnly(Side.CLIENT)
private void createWorldScene() {
if (this.screen == null || this.screen.getWorld() == null)
return;
isValid = true;
World world = this.screen.getWorld();
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int minZ = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;
int maxZ = Integer.MIN_VALUE;
for (BlockPos pos : validPos) {
minX = Math.min(minX, pos.getX());
minY = Math.min(minY, pos.getY());
minZ = Math.min(minZ, pos.getZ());
maxX = Math.max(maxX, pos.getX());
maxY = Math.max(maxY, pos.getY());
maxZ = Math.max(maxZ, pos.getZ());
}
if (FBO == null) {
FBO = new Framebuffer(RESOLUTION, RESOLUTION, true);
}
TrackedDummyWorld dummyWorld = new TrackedDummyWorld(world);
dummyWorld.setRenderFilter(pos -> validPos.contains(pos));
worldSceneRenderer = new FBOWorldSceneRenderer(dummyWorld, FBO);
worldSceneRenderer.addRenderedBlocks(validPos, null);
center = new Vector3f((minX + maxX) / 2f + 0.5f, (minY + maxY) / 2f + 0.5f, (minZ + maxZ) / 2f + 0.5f);
worldSceneRenderer.setCameraLookAt(center, 10 / scale, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
worldSceneRenderer.setBeforeWorldRender(this::renderBefore);
worldSceneRenderer.setAfterWorldRender(this::renderAfter);
worldSceneRenderer.setOnLookingAt(rayTrace -> renderBlockOverLay(rayTrace.getBlockPos()));
}
use of gregtech.client.utils.TrackedDummyWorld in project GregTech by GregTechCEu.
the class MultiblockInfoRecipeWrapper method setRecipeLayout.
public void setRecipeLayout(RecipeLayout layout, IGuiHelper guiHelper) {
this.recipeLayout = layout;
this.slot = guiHelper.drawableBuilder(GuiTextures.SLOT.imageLocation, 0, 0, SLOT_SIZE, SLOT_SIZE).setTextureSize(SLOT_SIZE, SLOT_SIZE).build();
this.infoIcon = guiHelper.drawableBuilder(GuiTextures.INFO_ICON.imageLocation, 0, 0, ICON_SIZE, ICON_SIZE).setTextureSize(ICON_SIZE, ICON_SIZE).build();
IDrawable border = layout.getRecipeCategory().getBackground();
preparePlaceForParts(border.getHeight());
if (Mouse.getEventDWheel() == 0 || lastWrapper != this) {
selected = null;
this.predicates.clear();
this.father = null;
lastWrapper = this;
this.nextLayerButton.x = border.getWidth() - (ICON_SIZE + RIGHT_PADDING);
this.buttonPreviousPattern.x = border.getWidth() - ((2 * ICON_SIZE) + RIGHT_PADDING + 1);
this.buttonNextPattern.x = border.getWidth() - (ICON_SIZE + RIGHT_PADDING);
this.buttonPreviousPattern.enabled = false;
this.buttonNextPattern.enabled = patterns.length > 1;
Vector3f size = ((TrackedDummyWorld) getCurrentRenderer().world).getSize();
float max = Math.max(Math.max(Math.max(size.x, size.y), size.z), 1);
this.zoom = (float) (3.5 * Math.sqrt(max));
this.rotationYaw = 20.0f;
this.rotationPitch = 50f;
this.currentRendererPage = 0;
setNextLayer(-1);
} else {
zoom = (float) MathHelper.clamp(zoom + (Mouse.getEventDWheel() < 0 ? 0.5 : -0.5), 3, 999);
setNextLayer(getLayerIndex());
if (predicates != null && predicates.size() > 0) {
setItemStackGroup();
}
}
if (getCurrentRenderer() != null) {
TrackedDummyWorld world = (TrackedDummyWorld) getCurrentRenderer().world;
resetCenter(world);
}
updateParts();
}
use of gregtech.client.utils.TrackedDummyWorld in project GregTech by GregTechCEu.
the class MultiblockInfoRecipeWrapper method setNextLayer.
private void setNextLayer(int newLayer) {
this.layerIndex = newLayer;
this.nextLayerButton.displayString = "L:" + (layerIndex == -1 ? "A" : Integer.toString(layerIndex + 1));
WorldSceneRenderer renderer = getCurrentRenderer();
if (renderer != null) {
TrackedDummyWorld world = ((TrackedDummyWorld) renderer.world);
resetCenter(world);
renderer.renderedBlocksMap.clear();
int minY = (int) world.getMinPos().getY();
Collection<BlockPos> renderBlocks;
if (newLayer == -1) {
renderBlocks = world.renderedBlocks;
} else {
renderBlocks = world.renderedBlocks.stream().filter(pos -> pos.getY() - minY == newLayer).collect(Collectors.toSet());
}
renderer.addRenderedBlocks(renderBlocks, null);
}
}
Aggregations