use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase 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.api.metatileentity.multiblock.MultiblockControllerBase 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);
}
}
Aggregations