use of gregtech.api.metatileentity.multiblock.IMultiblockPart in project GregTech by GregTechCEu.
the class MachineSceneWidget method updateScene.
private void updateScene() {
if (!mte.isValid())
return;
World world = mte.getWorld();
if (worldSceneRenderer != null) {
worldSceneRenderer.releaseFBO();
}
worldSceneRenderer = new FBOWorldSceneRenderer(world, 1080, 1080);
worldSceneRenderer.setAfterWorldRender(this::renderBlockOverLay);
cores = new HashSet<>();
around = new HashSet<>();
cores.add(pos);
if (mte instanceof MultiblockControllerBase) {
PatternMatchContext context = ((MultiblockControllerBase) mte).structurePattern.checkPatternFastAt(world, pos, mte.getFrontFacing().getOpposite());
if (context != null) {
List<BlockPos> validPos = ((MultiblockControllerBase) mte).structurePattern.cache.keySet().stream().map(BlockPos::fromLong).collect(Collectors.toList());
Set<IMultiblockPart> parts = context.getOrCreate("MultiblockParts", HashSet::new);
for (IMultiblockPart part : parts) {
if (part instanceof MetaTileEntity) {
cores.add(((MetaTileEntity) part).getPos());
}
}
for (EnumFacing facing : EnumFacing.VALUES) {
cores.forEach(pos -> around.add(pos.offset(facing)));
}
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 vPos : validPos) {
around.add(vPos);
minX = Math.min(minX, vPos.getX());
minY = Math.min(minY, vPos.getY());
minZ = Math.min(minZ, vPos.getZ());
maxX = Math.max(maxX, vPos.getX());
maxY = Math.max(maxY, vPos.getY());
maxZ = Math.max(maxZ, vPos.getZ());
}
around.removeAll(cores);
center = new Vector3f((minX + maxX) / 2f, (minY + maxY) / 2f, (minZ + maxZ) / 2f);
} else {
for (EnumFacing facing : EnumFacing.VALUES) {
around.add(pos.offset(facing));
}
center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f);
}
} else {
for (EnumFacing facing : EnumFacing.VALUES) {
around.add(pos.offset(facing));
}
center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f);
}
worldSceneRenderer.addRenderedBlocks(cores, null);
worldSceneRenderer.addRenderedBlocks(around, this::aroundBlocksRenderHook);
worldSceneRenderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
}
use of gregtech.api.metatileentity.multiblock.IMultiblockPart in project GregTech by GregTechCEu.
the class FakeGuiPluginBehavior method getRealMTE.
public MetaTileEntity getRealMTE() {
MetaTileEntity target = this.holder.getMetaTileEntity();
if (target instanceof MultiblockControllerBase && partIndex > 0) {
if (partPos != null) {
TileEntity entity = this.screen.getWorld().getTileEntity(partPos);
if (entity instanceof MetaTileEntityHolder) {
return ((MetaTileEntityHolder) entity).getMetaTileEntity();
} else {
partPos = null;
return null;
}
}
PatternMatchContext context = ((MultiblockControllerBase) target).structurePattern.checkPatternFastAt(target.getWorld(), target.getPos(), target.getFrontFacing().getOpposite());
if (context == null) {
return null;
}
Set<IMultiblockPart> rawPartsSet = context.getOrCreate("MultiblockParts", HashSet::new);
List<IMultiblockPart> parts = new ArrayList<>(rawPartsSet);
parts.sort(Comparator.comparing((it) -> ((MetaTileEntity) it).getPos().hashCode()));
if (parts.size() > partIndex - 1 && parts.get(partIndex - 1) instanceof MetaTileEntity) {
target = (MetaTileEntity) parts.get(partIndex - 1);
partPos = target.getPos();
} else {
return null;
}
}
return target;
}
use of gregtech.api.metatileentity.multiblock.IMultiblockPart in project GregTech by GregTechCEu.
the class MetaTileEntityCentralMonitor method formStructure.
@Override
protected void formStructure(PatternMatchContext context) {
super.formStructure(context);
lastUpdate = 0;
currentEnergyNet = new WeakReference<>(null);
activeNodes = new ArrayList<>();
netCovers = new HashSet<>();
remoteCovers = new HashSet<>();
inputEnergy = new EnergyContainerList(this.getAbilities(MultiblockAbility.INPUT_ENERGY));
width = 0;
checkCovers();
for (IMultiblockPart part : this.getMultiblockParts()) {
if (part instanceof MetaTileEntityMonitorScreen) {
width++;
}
}
width = width / height;
screens = new MetaTileEntityMonitorScreen[width][height];
for (IMultiblockPart part : this.getMultiblockParts()) {
if (part instanceof MetaTileEntityMonitorScreen) {
MetaTileEntityMonitorScreen screen = (MetaTileEntityMonitorScreen) part;
screens[screen.getX()][screen.getY()] = screen;
}
}
writeCustomData(GregtechDataCodes.UPDATE_ALL, packetBuffer -> {
packetBuffer.writeInt(width);
packetBuffer.writeInt(height);
writeCovers(packetBuffer);
writeParts(packetBuffer);
});
}
Aggregations