use of gregtech.client.renderer.scene.WorldSceneRenderer in project GregTech by GregTechCEu.
the class JEIOptional method getWorldSceneRenderer.
@Optional.Method(modid = "jei")
public static WorldSceneRenderer getWorldSceneRenderer(MultiblockControllerBase controllerBase) {
IRecipeRegistry rr = GTJeiPlugin.jeiRuntime.getRecipeRegistry();
IFocus<ItemStack> focus = rr.createFocus(IFocus.Mode.INPUT, controllerBase.getStackForm());
return rr.getRecipeCategories(focus).stream().map(c -> (IRecipeCategory<IRecipeWrapper>) c).map(c -> rr.getRecipeWrappers(c, focus)).flatMap(List::stream).filter(MultiblockInfoRecipeWrapper.class::isInstance).findFirst().map(MultiblockInfoRecipeWrapper.class::cast).map(MultiblockInfoRecipeWrapper::getCurrentRenderer).orElse(null);
}
use of gregtech.client.renderer.scene.WorldSceneRenderer in project GregTech by GregTechCEu.
the class MultiblockInfoRecipeWrapper method toggleNextLayer.
private void toggleNextLayer() {
WorldSceneRenderer renderer = getCurrentRenderer();
int height = (int) ((TrackedDummyWorld) renderer.world).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.client.renderer.scene.WorldSceneRenderer 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.renderer.scene.WorldSceneRenderer in project GregTech by GregTechCEu.
the class AdvancedMonitorPluginBehavior method update.
@Override
public void update() {
super.update();
if (this.screen.getOffsetTimer() % 20 == 0) {
if (this.screen.getWorld().isRemote) {
// check connections
if (worldSceneRenderer == null && validPos != null && validPos.size() > 0) {
createWorldScene();
}
if (this.connect && worldSceneRenderer != null && this.screen.getController() instanceof MetaTileEntityCentralMonitor) {
if (connections == null)
connections = new HashMap<>();
connections.clear();
for (MetaTileEntityMonitorScreen[] monitorScreens : ((MetaTileEntityCentralMonitor) this.screen.getController()).screens) {
for (MetaTileEntityMonitorScreen screen : monitorScreens) {
if (screen != null && screen.plugin instanceof FakeGuiPluginBehavior && ((FakeGuiPluginBehavior) screen.plugin).getHolder() == this.holder) {
MetaTileEntity met = ((FakeGuiPluginBehavior) screen.plugin).getRealMTE();
if (met != null) {
BlockPos pos = met.getPos();
Pair<List<MetaTileEntityMonitorScreen>, Vector3f> tuple = connections.getOrDefault(pos, new MutablePair<>(new ArrayList<>(), null));
tuple.getLeft().add(screen);
connections.put(pos, tuple);
}
}
}
}
}
} else {
// check multi-block valid
if (holder != null && holder.getMetaTileEntity() instanceof MultiblockControllerBase) {
MultiblockControllerBase entity = (MultiblockControllerBase) holder.getMetaTileEntity();
if (entity.isStructureFormed()) {
if (!isValid) {
PatternMatchContext result = entity.structurePattern.checkPatternFastAt(entity.getWorld(), entity.getPos(), entity.getFrontFacing().getOpposite());
if (result != null) {
validPos = entity.structurePattern.cache.keySet().stream().map(BlockPos::fromLong).collect(Collectors.toSet());
writePluginData(GregtechDataCodes.UPDATE_ADVANCED_VALID_POS, buf -> {
buf.writeVarInt(validPos.size());
for (BlockPos pos : validPos) {
buf.writeBlockPos(pos);
}
});
isValid = true;
} else {
validPos = Collections.emptySet();
}
}
} else if (isValid) {
writePluginData(GregtechDataCodes.UPDATE_ADVANCED_VALID_POS, buf -> buf.writeVarInt(0));
isValid = false;
}
}
}
}
if (this.screen.getWorld().isRemote && spin > 0 && lastMouse == null) {
rotationPitch = (int) ((rotationPitch + spin * 4) % 360);
}
}
use of gregtech.client.renderer.scene.WorldSceneRenderer 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