|
9 | 9 | import com.mojang.blaze3d.systems.RenderSystem;
|
10 | 10 | import com.mojang.blaze3d.vertex.PoseStack;
|
11 | 11 | import com.mojang.blaze3d.vertex.VertexConsumer;
|
| 12 | +import com.mojang.math.Matrix4f; |
12 | 13 | import com.mojang.math.Vector3f;
|
13 | 14 |
|
14 | 15 | import net.minecraft.ChatFormatting;
|
15 | 16 | import net.minecraft.client.Minecraft;
|
| 17 | +import net.minecraft.client.renderer.LightTexture; |
16 | 18 | import net.minecraft.client.renderer.MultiBufferSource;
|
17 | 19 | import net.minecraft.client.renderer.RenderType;
|
18 | 20 | import net.minecraft.client.renderer.entity.EntityRenderer;
|
19 | 21 | import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
20 | 22 | import net.minecraft.client.renderer.texture.OverlayTexture;
|
| 23 | +import net.minecraft.core.BlockPos; |
21 | 24 | import net.minecraft.core.Direction;
|
22 | 25 | import net.minecraft.resources.ResourceLocation;
|
23 | 26 | import net.minecraft.util.Mth;
|
| 27 | +import net.minecraft.world.entity.Entity; |
24 | 28 | import net.minecraft.world.entity.EquipmentSlot;
|
25 | 29 | import net.minecraft.world.entity.LivingEntity;
|
| 30 | +import net.minecraft.world.entity.Mob; |
26 | 31 | import net.minecraft.world.entity.Pose;
|
27 | 32 | import net.minecraft.world.entity.player.Player;
|
28 | 33 | import net.minecraft.world.entity.player.PlayerModelPart;
|
29 | 34 | import net.minecraft.world.item.ItemStack;
|
| 35 | +import net.minecraft.world.level.LightLayer; |
| 36 | +import net.minecraft.world.phys.Vec3; |
30 | 37 | import net.minecraftforge.fml.ModList;
|
31 | 38 | import software.bernie.geckolib3.compat.PatchouliCompat;
|
32 | 39 | import software.bernie.geckolib3.core.engine.Animator;
|
@@ -141,6 +148,12 @@ packedLightIn, getPackedOverlay(entity, 0), (float) renderColor.getRed() / 255f,
|
141 | 148 | f7, netHeadYaw, headPitch);
|
142 | 149 | }
|
143 | 150 | }
|
| 151 | + if (entity instanceof Mob) { |
| 152 | + Entity leashHolder = ((Mob) entity).getLeashHolder(); |
| 153 | + if (leashHolder != null) { |
| 154 | + this.renderLeash(entity, partialTicks, stack, bufferIn, leashHolder); |
| 155 | + } |
| 156 | + } |
144 | 157 | if (ModList.get().isLoaded("patchouli")) {
|
145 | 158 | PatchouliCompat.patchouliLoaded(stack);
|
146 | 159 | }
|
@@ -267,4 +280,67 @@ public ResourceLocation getTextureLocation(T instance) {
|
267 | 280 | public final boolean addLayer(GeoLayerRenderer<T> layer) {
|
268 | 281 | return this.layerRenderers.add(layer);
|
269 | 282 | }
|
| 283 | + |
| 284 | + private <E extends Entity> void renderLeash(T entity, float partialTicks, PoseStack poseStack, |
| 285 | + MultiBufferSource buffer, E leashHolder) { |
| 286 | + poseStack.pushPose(); |
| 287 | + Vec3 vec3 = leashHolder.getRopeHoldPosition(partialTicks); |
| 288 | + double d0 = (double) (Mth.lerp(partialTicks, entity.yBodyRot, entity.yBodyRotO) * ((float) Math.PI / 180F)) |
| 289 | + + (Math.PI / 2D); |
| 290 | + Vec3 vec31 = entity.getLeashOffset(); |
| 291 | + double d1 = Math.cos(d0) * vec31.z + Math.sin(d0) * vec31.x; |
| 292 | + double d2 = Math.sin(d0) * vec31.z - Math.cos(d0) * vec31.x; |
| 293 | + double d3 = Mth.lerp(partialTicks, entity.xo, entity.getX()) + d1; |
| 294 | + double d4 = Mth.lerp(partialTicks, entity.yo, entity.getY()) + vec31.y; |
| 295 | + double d5 = Mth.lerp(partialTicks, entity.zo, entity.getZ()) + d2; |
| 296 | + poseStack.translate(d1, vec31.y, d2); |
| 297 | + float f = (float) (vec3.x - d3); |
| 298 | + float f1 = (float) (vec3.y - d4); |
| 299 | + float f2 = (float) (vec3.z - d5); |
| 300 | + VertexConsumer vertexconsumer = buffer.getBuffer(RenderType.leash()); |
| 301 | + Matrix4f matrix4f = poseStack.last().pose(); |
| 302 | + float f4 = Mth.fastInvSqrt(f * f + f2 * f2) * 0.025F / 2.0F; |
| 303 | + float f5 = f2 * f4; |
| 304 | + float f6 = f * f4; |
| 305 | + BlockPos blockpos = new BlockPos(entity.getEyePosition(partialTicks)); |
| 306 | + BlockPos blockpos1 = new BlockPos(leashHolder.getEyePosition(partialTicks)); |
| 307 | + int i = this.getBlockLightLevel(entity, blockpos); |
| 308 | + int j = this.getLeashHolderBlockLightLevel(leashHolder, blockpos1); |
| 309 | + int k = entity.level.getBrightness(LightLayer.SKY, blockpos); |
| 310 | + int l = entity.level.getBrightness(LightLayer.SKY, blockpos1); |
| 311 | + |
| 312 | + for (int i1 = 0; i1 <= 24; ++i1) { |
| 313 | + addVertexPair(vertexconsumer, matrix4f, f, f1, f2, i, j, k, l, 0.025F, 0.025F, f5, f6, i1, false); |
| 314 | + } |
| 315 | + |
| 316 | + for (int j1 = 24; j1 >= 0; --j1) { |
| 317 | + addVertexPair(vertexconsumer, matrix4f, f, f1, f2, i, j, k, l, 0.025F, 0.0F, f5, f6, j1, true); |
| 318 | + } |
| 319 | + |
| 320 | + poseStack.popPose(); |
| 321 | + } |
| 322 | + |
| 323 | + private int getLeashHolderBlockLightLevel(Entity leashHolder, BlockPos pos) { |
| 324 | + return leashHolder.isOnFire() ? 15 : leashHolder.level.getBrightness(LightLayer.BLOCK, pos); |
| 325 | + } |
| 326 | + |
| 327 | + private static void addVertexPair(VertexConsumer vertexConsumer, Matrix4f matrix, float xDiff, float yDiff, |
| 328 | + float zDiff, int entityLightLevel, int holderLightLevel, int entitySkyLight, int holderSkyLight, |
| 329 | + float p_174317_, float p_174318_, float p_174319_, float p_174320_, int p_174321_, boolean p_174322_) { |
| 330 | + float f = (float) p_174321_ / 24.0F; |
| 331 | + int i = (int) Mth.lerp(f, (float) entityLightLevel, (float) holderLightLevel); |
| 332 | + int j = (int) Mth.lerp(f, (float) entitySkyLight, (float) holderSkyLight); |
| 333 | + int k = LightTexture.pack(i, j); |
| 334 | + float f1 = p_174321_ % 2 == (p_174322_ ? 1 : 0) ? 0.7F : 1.0F; |
| 335 | + float f2 = 0.5F * f1; |
| 336 | + float f3 = 0.4F * f1; |
| 337 | + float f4 = 0.3F * f1; |
| 338 | + float f5 = xDiff * f; |
| 339 | + float f6 = yDiff > 0.0F ? yDiff * f * f : yDiff - yDiff * (1.0F - f) * (1.0F - f); |
| 340 | + float f7 = zDiff * f; |
| 341 | + vertexConsumer.vertex(matrix, f5 - p_174319_, f6 + p_174318_, f7 + p_174320_).color(f2, f3, f4, 1.0F).uv2(k) |
| 342 | + .endVertex(); |
| 343 | + vertexConsumer.vertex(matrix, f5 + p_174319_, f6 + p_174317_ - p_174318_, f7 - p_174320_) |
| 344 | + .color(f2, f3, f4, 1.0F).uv2(k).endVertex(); |
| 345 | + } |
270 | 346 | }
|
0 commit comments