-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix proposal for #9063 and #9058 #9127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fabien-gigante
wants to merge
8
commits into
Creators-of-Create:mc1.20.1/dev
Choose a base branch
from
fabien-gigante:mc1.20.1/fix-#9063-#9058
base: mc1.20.1/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
05bdcf6
Update ValueBoxRenderer.java
fabien-gigante 4f36389
Update ValueBoxRenderer.java
fabien-gigante 6fae8a0
Fix gear rendering in ValueBoxRenderer.java
fabien-gigante ff228ff
Defensive check
fabien-gigante f42c2f2
can't assume block getter is nullable...
fabien-gigante 28096d4
can't assume blockgetter is nullable
fabien-gigante 5a97973
Reverting to vertex-only transform
fabien-gigante ad39c93
Revert to vertex-only transform
fabien-gigante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,22 @@ | ||
| package com.simibubi.create.foundation.blockEntity.behaviour; | ||
|
|
||
| import org.joml.Matrix3f; | ||
|
|
||
| import com.mojang.blaze3d.vertex.PoseStack; | ||
| import com.simibubi.create.content.kinetics.simpleRelays.AbstractSimpleShaftBlock; | ||
|
|
||
| import dev.engine_room.flywheel.lib.transform.TransformStack; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.renderer.MultiBufferSource; | ||
| import net.minecraft.client.renderer.entity.ItemRenderer; | ||
| import net.minecraft.client.renderer.texture.OverlayTexture; | ||
| import net.minecraft.client.resources.model.BakedModel; | ||
| import net.minecraft.tags.BlockTags; | ||
| import net.minecraft.util.Mth; | ||
| import net.minecraft.core.BlockPos; | ||
| import net.minecraft.core.Direction; | ||
| import net.minecraft.world.item.BlockItem; | ||
| import net.minecraft.world.item.Item; | ||
| import net.minecraft.world.item.ItemDisplayContext; | ||
| import net.minecraft.world.item.ItemStack; | ||
| import net.minecraft.world.level.EmptyBlockGetter; | ||
| import net.minecraft.world.level.block.Block; | ||
| import net.minecraft.world.level.block.Blocks; | ||
| import net.minecraft.world.level.block.FenceBlock; | ||
| import net.minecraft.world.phys.shapes.VoxelShape; | ||
| import com.simibubi.create.content.kinetics.simpleRelays.AbstractSimpleShaftBlock; | ||
|
|
||
| public class ValueBoxRenderer { | ||
|
|
||
|
|
@@ -30,66 +27,35 @@ public static void renderItemIntoValueBox(ItemStack filter, PoseStack ms, MultiB | |
| BakedModel modelWithOverrides = itemRenderer.getModel(filter, null, null, 0); | ||
| boolean blockItem = modelWithOverrides.isGui3d(); | ||
| float scale = (!blockItem ? .5f : 1f) + 1 / 64f; | ||
| float zOffset = (!blockItem ? -.15f : 0) + customZOffset(filter.getItem()); | ||
| float zOffset = !blockItem ? -.15f : customZOffset(filter.getItem()); | ||
| ms.scale(scale, scale, scale); | ||
| ms.translate(0, 0, zOffset); | ||
| itemRenderer.render(filter, ItemDisplayContext.FIXED, false, ms, buffer, light, overlay, modelWithOverrides); | ||
| } | ||
|
|
||
| public static void renderFlatItemIntoValueBox(ItemStack filter, PoseStack ms, MultiBufferSource buffer, int light, | ||
| int overlay) { | ||
| if (filter.isEmpty()) | ||
| return; | ||
|
|
||
| int bl = light >> 4 & 0xf; | ||
| int sl = light >> 20 & 0xf; | ||
| int itemLight = Mth.floor(sl + .5) << 20 | (Mth.floor(bl + .5) & 0xf) << 4; | ||
|
|
||
| ms.pushPose(); | ||
| TransformStack.of(ms) | ||
| .rotateXDegrees(230); | ||
| Matrix3f copy = new Matrix3f(ms.last() | ||
| .normal()); | ||
| ms.popPose(); | ||
|
|
||
| ms.pushPose(); | ||
| public static void renderFlatItemIntoValueBox(ItemStack filter, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { | ||
| if (filter.isEmpty()) return; | ||
| TransformStack.of(ms) | ||
| .translate(0, 0, -1 / 4f) | ||
| .translate(0, 0, 1 / 32f + .001) | ||
| .rotateYDegrees(180); | ||
|
|
||
| PoseStack squashedMS = new PoseStack(); | ||
| squashedMS.last() | ||
| .pose() | ||
| .mul(ms.last() | ||
| .pose()); | ||
| squashedMS.scale(.5f, .5f, 1 / 1024f); | ||
| squashedMS.last() | ||
| .normal() | ||
| .set(copy); | ||
| .translate(0, 0, -1 / 4f + 1 / 32f + .001) | ||
| .rotateYDegrees(180) | ||
| .scale(.5f, .5f, .5f); | ||
| // Then, squash it flat, but leave the normals unaffected by this last transform | ||
| ms.last().pose().scale(1f, 1f, 1 / 512f); | ||
| Minecraft mc = Minecraft.getInstance(); | ||
| mc.getItemRenderer() | ||
| .renderStatic(filter, ItemDisplayContext.GUI, itemLight, OverlayTexture.NO_OVERLAY, squashedMS, buffer, mc.level, 0); | ||
|
|
||
| ms.popPose(); | ||
| ItemRenderer itemRenderer = mc.getItemRenderer(); | ||
| itemRenderer.renderStatic(filter, ItemDisplayContext.GUI, light, OverlayTexture.NO_OVERLAY, ms, buffer, mc.level, 0); | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| private static float customZOffset(Item item) { | ||
| float nudge = -.1f; | ||
| if (item instanceof BlockItem) { | ||
| Block block = ((BlockItem) item).getBlock(); | ||
| if (block instanceof AbstractSimpleShaftBlock) | ||
| return nudge; | ||
| if (block instanceof FenceBlock) | ||
| return nudge; | ||
| if (block.builtInRegistryHolder() | ||
| .is(BlockTags.BUTTONS)) | ||
| return nudge; | ||
| if (block == Blocks.END_ROD) | ||
| return nudge; | ||
| } | ||
| return 0; | ||
| final float nudge = -.1f; | ||
| if (!(item instanceof BlockItem blockItem)) return 0f; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit formatting. I'd prefer the returns on separate lines |
||
| // Special case : gears are thick enough but need to be offset anyway | ||
| Block block = blockItem.getBlock(); | ||
| if (block instanceof AbstractSimpleShaftBlock) return nudge; | ||
| // General case : determine offset based on shape thickness | ||
| VoxelShape shape = block.defaultBlockState().getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VoxelShape methods can be extremely expensive. Please include spark profiles of before/after |
||
| if (shape.isEmpty()) return 0f; | ||
| double thickness = shape.max(Direction.Axis.Z) - shape.min(Direction.Axis.Z); | ||
| return thickness <= .25 ? nudge : 0f; | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will likely just obfuscate other issues, please undo