use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBox in project Create by Creators-of-Create.
the class GoggleOverlayRenderer method renderOverlay.
public static void renderOverlay(ForgeIngameGui gui, PoseStack poseStack, float partialTicks, int width, int height) {
HitResult objectMouseOver = Minecraft.getInstance().hitResult;
if (!(objectMouseOver instanceof BlockHitResult)) {
lastHovered = null;
hoverTicks = 0;
return;
}
for (OutlineEntry entry : outlines.values()) {
if (!entry.isAlive())
continue;
Outline outline = entry.getOutline();
if (outline instanceof ValueBox && !((ValueBox) outline).isPassive)
return;
}
BlockHitResult result = (BlockHitResult) objectMouseOver;
Minecraft mc = Minecraft.getInstance();
ClientLevel world = mc.level;
BlockPos pos = result.getBlockPos();
ItemStack headSlot = mc.player.getItemBySlot(EquipmentSlot.HEAD);
BlockEntity te = world.getBlockEntity(pos);
if (lastHovered == null || lastHovered.equals(pos))
hoverTicks++;
else
hoverTicks = 0;
lastHovered = pos;
boolean wearingGoggles = AllItems.GOGGLES.isIn(headSlot);
for (Supplier<Boolean> supplier : customGogglePredicates) wearingGoggles |= supplier.get();
boolean hasGoggleInformation = te instanceof IHaveGoggleInformation;
boolean hasHoveringInformation = te instanceof IHaveHoveringInformation;
boolean goggleAddedInformation = false;
boolean hoverAddedInformation = false;
List<Component> tooltip = new ArrayList<>();
if (hasGoggleInformation && wearingGoggles) {
IHaveGoggleInformation gte = (IHaveGoggleInformation) te;
goggleAddedInformation = gte.addToGoggleTooltip(tooltip, mc.player.isShiftKeyDown());
}
if (hasHoveringInformation) {
if (!tooltip.isEmpty())
tooltip.add(TextComponent.EMPTY);
IHaveHoveringInformation hte = (IHaveHoveringInformation) te;
hoverAddedInformation = hte.addToTooltip(tooltip, mc.player.isShiftKeyDown());
if (goggleAddedInformation && !hoverAddedInformation)
tooltip.remove(tooltip.size() - 1);
}
if (te instanceof IDisplayAssemblyExceptions) {
boolean exceptionAdded = ((IDisplayAssemblyExceptions) te).addExceptionToTooltip(tooltip);
if (exceptionAdded) {
hasHoveringInformation = true;
hoverAddedInformation = true;
}
}
// break early if goggle or hover returned false when present
if ((hasGoggleInformation && !goggleAddedInformation) && (hasHoveringInformation && !hoverAddedInformation))
return;
// check for piston poles if goggles are worn
BlockState state = world.getBlockState(pos);
if (wearingGoggles && AllBlocks.PISTON_EXTENSION_POLE.has(state)) {
Direction[] directions = Iterate.directionsInAxis(state.getValue(PistonExtensionPoleBlock.FACING).getAxis());
int poles = 1;
boolean pistonFound = false;
for (Direction dir : directions) {
int attachedPoles = PistonExtensionPoleBlock.PlacementHelper.get().attachedPoles(world, pos, dir);
poles += attachedPoles;
pistonFound |= world.getBlockState(pos.relative(dir, attachedPoles + 1)).getBlock() instanceof MechanicalPistonBlock;
}
if (!pistonFound)
return;
if (!tooltip.isEmpty())
tooltip.add(TextComponent.EMPTY);
tooltip.add(IHaveGoggleInformation.componentSpacing.plainCopy().append(Lang.translate("gui.goggles.pole_length")).append(new TextComponent(" " + poles)));
}
if (tooltip.isEmpty())
return;
poseStack.pushPose();
int tooltipTextWidth = 0;
for (FormattedText textLine : tooltip) {
int textLineWidth = mc.font.width(textLine);
if (textLineWidth > tooltipTextWidth)
tooltipTextWidth = textLineWidth;
}
int tooltipHeight = 8;
if (tooltip.size() > 1) {
// gap between title lines and next lines
tooltipHeight += 2;
tooltipHeight += (tooltip.size() - 1) * 10;
}
CClient cfg = AllConfigs.CLIENT;
int posX = width / 2 + cfg.overlayOffsetX.get();
int posY = height / 2 + cfg.overlayOffsetY.get();
posX = Math.min(posX, width - tooltipTextWidth - 20);
posY = Math.min(posY, height - tooltipHeight - 20);
float fade = Mth.clamp((hoverTicks + partialTicks) / 12f, 0, 1);
Boolean useCustom = cfg.overlayCustomColor.get();
Color colorBackground = useCustom ? new Color(cfg.overlayBackgroundColor.get()) : Theme.c(Theme.Key.VANILLA_TOOLTIP_BACKGROUND).scaleAlpha(.75f);
Color colorBorderTop = useCustom ? new Color(cfg.overlayBorderColorTop.get()) : Theme.c(Theme.Key.VANILLA_TOOLTIP_BORDER, true).copy();
Color colorBorderBot = useCustom ? new Color(cfg.overlayBorderColorBot.get()) : Theme.c(Theme.Key.VANILLA_TOOLTIP_BORDER, false).copy();
if (fade < 1) {
poseStack.translate((1 - fade) * Math.signum(cfg.overlayOffsetX.get() + .5f) * 4, 0, 0);
colorBackground.scaleAlpha(fade);
colorBorderTop.scaleAlpha(fade);
colorBorderBot.scaleAlpha(fade);
}
RemovedGuiUtils.drawHoveringText(poseStack, tooltip, posX, posY, width, height, -1, colorBackground.getRGB(), colorBorderTop.getRGB(), colorBorderBot.getRGB(), mc.font);
ItemStack item = AllItems.GOGGLES.asStack();
GuiGameElement.of(item).at(posX + 10, posY - 16, 450).render(poseStack);
poseStack.popPose();
}
use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBox in project Create by Creators-of-Create.
the class EdgeInteractionRenderer method tick.
public static void tick() {
Minecraft mc = Minecraft.getInstance();
HitResult target = mc.hitResult;
if (target == null || !(target instanceof BlockHitResult))
return;
BlockHitResult result = (BlockHitResult) target;
ClientLevel world = mc.level;
BlockPos pos = result.getBlockPos();
Player player = mc.player;
ItemStack heldItem = player.getMainHandItem();
if (player.isShiftKeyDown())
return;
EdgeInteractionBehaviour behaviour = TileEntityBehaviour.get(world, pos, EdgeInteractionBehaviour.TYPE);
if (behaviour == null)
return;
if (behaviour.requiredItem.orElse(heldItem.getItem()) != heldItem.getItem())
return;
Direction face = result.getDirection();
List<Direction> connectiveSides = EdgeInteractionHandler.getConnectiveSides(world, pos, face, behaviour);
if (connectiveSides.isEmpty())
return;
Direction closestEdge = connectiveSides.get(0);
double bestDistance = Double.MAX_VALUE;
Vec3 center = VecHelper.getCenterOf(pos);
for (Direction direction : connectiveSides) {
double distance = Vec3.atLowerCornerOf(direction.getNormal()).subtract(target.getLocation().subtract(center)).length();
if (distance > bestDistance)
continue;
bestDistance = distance;
closestEdge = direction;
}
AABB bb = EdgeInteractionHandler.getBB(pos, closestEdge);
boolean hit = bb.contains(target.getLocation());
ValueBox box = new ValueBox(TextComponent.EMPTY, bb.move(-pos.getX(), -pos.getY(), -pos.getZ()), pos);
Vec3 textOffset = Vec3.ZERO;
boolean positive = closestEdge.getAxisDirection() == AxisDirection.POSITIVE;
if (positive) {
if (face.getAxis().isHorizontal()) {
if (closestEdge.getAxis().isVertical())
textOffset = textOffset.add(0, -128, 0);
else
textOffset = textOffset.add(-128, 0, 0);
} else
textOffset = textOffset.add(-128, 0, 0);
}
box.offsetLabel(textOffset).withColors(0x7A6A2C, 0xB79D64).passive(!hit);
CreateClient.OUTLINER.showValueBox("edge", box).lineWidth(1 / 64f).withFaceTexture(hit ? AllSpecialTextures.THIN_CHECKERED : null).highlightFace(face);
}
use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBox in project Create by Creators-of-Create.
the class FilteringRenderer method tick.
public static void tick() {
Minecraft mc = Minecraft.getInstance();
HitResult target = mc.hitResult;
if (target == null || !(target instanceof BlockHitResult))
return;
BlockHitResult result = (BlockHitResult) target;
ClientLevel world = mc.level;
BlockPos pos = result.getBlockPos();
BlockState state = world.getBlockState(pos);
FilteringBehaviour behaviour = TileEntityBehaviour.get(world, pos, FilteringBehaviour.TYPE);
if (mc.player.isShiftKeyDown())
return;
if (behaviour == null)
return;
if (behaviour instanceof SidedFilteringBehaviour) {
behaviour = ((SidedFilteringBehaviour) behaviour).get(result.getDirection());
if (behaviour == null)
return;
}
if (!behaviour.isActive())
return;
if (behaviour.slotPositioning instanceof ValueBoxTransform.Sided)
((Sided) behaviour.slotPositioning).fromSide(result.getDirection());
if (!behaviour.slotPositioning.shouldRender(state))
return;
ItemStack filter = behaviour.getFilter();
boolean isFilterSlotted = filter.getItem() instanceof FilterItem;
boolean showCount = behaviour.isCountVisible();
boolean fluids = behaviour.fluidFilter;
Component label = isFilterSlotted ? TextComponent.EMPTY : Lang.translate(behaviour.recipeFilter ? "logistics.recipe_filter" : fluids ? "logistics.fluid_filter" : "logistics.filter");
boolean hit = behaviour.slotPositioning.testHit(state, target.getLocation().subtract(Vec3.atLowerCornerOf(pos)));
AABB emptyBB = new AABB(Vec3.ZERO, Vec3.ZERO);
AABB bb = isFilterSlotted ? emptyBB.inflate(.45f, .31f, .2f) : emptyBB.inflate(.25f);
ValueBox box = showCount ? new ItemValueBox(label, bb, pos, filter, behaviour.scrollableValue) : new ValueBox(label, bb, pos);
box.offsetLabel(behaviour.textShift).withColors(fluids ? 0x407088 : 0x7A6A2C, fluids ? 0x70adb5 : 0xB79D64).scrollTooltip(showCount && !isFilterSlotted ? new TextComponent("[").append(Lang.translate("action.scroll")).append("]") : TextComponent.EMPTY).passive(!hit);
CreateClient.OUTLINER.showValueBox(Pair.of("filter", pos), box.transform(behaviour.slotPositioning)).lineWidth(1 / 64f).withFaceTexture(hit ? AllSpecialTextures.THIN_CHECKERED : null).highlightFace(result.getDirection());
}
use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBox in project Create by Creators-of-Create.
the class LinkRenderer method tick.
public static void tick() {
Minecraft mc = Minecraft.getInstance();
HitResult target = mc.hitResult;
if (target == null || !(target instanceof BlockHitResult))
return;
BlockHitResult result = (BlockHitResult) target;
ClientLevel world = mc.level;
BlockPos pos = result.getBlockPos();
LinkBehaviour behaviour = TileEntityBehaviour.get(world, pos, LinkBehaviour.TYPE);
if (behaviour == null)
return;
Component freq1 = Lang.translate("logistics.firstFrequency");
Component freq2 = Lang.translate("logistics.secondFrequency");
for (boolean first : Iterate.trueAndFalse) {
AABB bb = new AABB(Vec3.ZERO, Vec3.ZERO).inflate(.25f);
Component label = first ? freq1 : freq2;
boolean hit = behaviour.testHit(first, target.getLocation());
ValueBoxTransform transform = first ? behaviour.firstSlot : behaviour.secondSlot;
ValueBox box = new ValueBox(label, bb, pos).withColors(0x601F18, 0xB73C2D).offsetLabel(behaviour.textShift).passive(!hit);
CreateClient.OUTLINER.showValueBox(Pair.of(Boolean.valueOf(first), pos), box.transform(transform)).lineWidth(1 / 64f).withFaceTexture(hit ? AllSpecialTextures.THIN_CHECKERED : null).highlightFace(result.getDirection());
}
}
use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBox in project Create by Creators-of-Create.
the class ScrollValueRenderer method addBox.
protected static void addBox(ClientLevel world, BlockPos pos, Direction face, ScrollValueBehaviour behaviour, boolean highlight) {
AABB bb = new AABB(Vec3.ZERO, Vec3.ZERO).inflate(.5f).contract(0, 0, -.5f).move(0, 0, -.125f);
Component label = behaviour.label;
ValueBox box;
if (behaviour instanceof ScrollOptionBehaviour) {
box = new IconValueBox(label, ((ScrollOptionBehaviour<?>) behaviour).getIconForSelected(), bb, pos);
} else {
box = new TextValueBox(label, bb, pos, new TextComponent(behaviour.formatValue()));
if (behaviour.unit != null)
box.subLabel(new TextComponent("(").append(behaviour.unit.apply(behaviour.scrollableValue)).append(")"));
}
box.scrollTooltip(new TextComponent("[").append(Lang.translate("action.scroll")).append("]"));
box.offsetLabel(behaviour.textShift.add(20, -10, 0)).withColors(0x5A5D5A, 0xB5B7B6).passive(!highlight);
CreateClient.OUTLINER.showValueBox(pos, box.transform(behaviour.slotPositioning)).lineWidth(1 / 64f).highlightFace(face);
}
Aggregations