use of gregtech.api.pattern.PatternMatchContext 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.pattern.PatternMatchContext 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.pattern.PatternMatchContext 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.api.pattern.PatternMatchContext in project GregTech by GregTechCEu.
the class MultiblockInfoRecipeWrapper method drawInfo.
@Override
public void drawInfo(@Nonnull 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, mouseX + recipeLayout.getPosX(), mouseY + recipeLayout.getPosY());
drawMultiblockName(recipeWidth);
// reset colors (so any elements render after this point are not dark)
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
int iconX = recipeWidth - (ICON_SIZE + RIGHT_PADDING);
int iconY = 49;
this.infoIcon.draw(minecraft, iconX, iconY);
this.drawInfoIcon = iconX <= mouseX && mouseX <= iconX + ICON_SIZE && iconY <= mouseY && mouseY <= iconY + ICON_SIZE;
// draw parts slots
for (int i = 0; i < MAX_PARTS; ++i) {
this.slot.draw(minecraft, SLOT_SIZE * i - (SLOTS_PER_ROW * SLOT_SIZE) * (i / SLOTS_PER_ROW) + (SLOT_SIZE / 2) - 2, sceneHeight + SLOT_SIZE * (i / SLOTS_PER_ROW));
}
// draw candidates slots
for (int i = 0; i < predicates.size(); i++) {
this.slot.draw(minecraft, 5 + (i / 6) * SLOT_SIZE, (i % 6) * SLOT_SIZE + 10);
}
// draw buttons
for (GuiButton button : buttons.keySet()) {
button.drawButton(minecraft, mouseX, mouseY, 0.0f);
}
tooltipBlockStack = null;
this.predicateTips = null;
RayTraceResult rayTraceResult = renderer.getLastTraceResult();
boolean insideView = mouseX >= 0 && mouseY >= 0 && mouseX < recipeWidth && mouseY < sceneHeight;
boolean leftClickHeld = Mouse.isButtonDown(0);
boolean rightClickHeld = Mouse.isButtonDown(1);
if (insideView) {
for (GuiButton button : buttons.keySet()) {
if (button.isMouseOver()) {
insideView = false;
break;
}
}
}
if (insideView) {
if (leftClickHeld) {
rotationPitch += mouseX - lastMouseX + 360;
rotationPitch = rotationPitch % 360;
rotationYaw = (float) MathHelper.clamp(rotationYaw + (mouseY - lastMouseY), -89.9, 89.9);
} else if (rightClickHeld) {
int mouseDeltaY = mouseY - lastMouseY;
if (Math.abs(mouseDeltaY) > 1) {
this.zoom = (float) MathHelper.clamp(zoom + (mouseDeltaY > 0 ? 0.5 : -0.5), 3, 999);
}
}
renderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
}
if (!(leftClickHeld || rightClickHeld) && rayTraceResult != null && !renderer.world.isAirBlock(rayTraceResult.getBlockPos())) {
IBlockState blockState = renderer.world.getBlockState(rayTraceResult.getBlockPos());
ItemStack itemStack = blockState.getBlock().getPickBlock(blockState, rayTraceResult, renderer.world, rayTraceResult.getBlockPos(), minecraft.player);
TraceabilityPredicate predicates = patterns[currentRendererPage].predicateMap.get(rayTraceResult.getBlockPos());
if (predicates != null) {
BlockWorldState worldState = new BlockWorldState();
worldState.update(renderer.world, rayTraceResult.getBlockPos(), new PatternMatchContext(), new HashMap<>(), new HashMap<>(), predicates);
for (TraceabilityPredicate.SimplePredicate common : predicates.common) {
if (common.test(worldState)) {
predicateTips = common.getToolTips(predicates);
break;
}
}
if (predicateTips == null) {
for (TraceabilityPredicate.SimplePredicate limit : predicates.limited) {
if (limit.test(worldState)) {
predicateTips = limit.getToolTips(predicates);
break;
}
}
}
}
if (!itemStack.isEmpty()) {
tooltipBlockStack = itemStack;
}
}
lastRender = System.currentTimeMillis();
this.lastMouseX = mouseX;
this.lastMouseY = mouseY;
GlStateManager.disableRescaleNormal();
GlStateManager.disableLighting();
RenderHelper.disableStandardItemLighting();
}
Aggregations