Skip to content

Commit b8485a0

Browse files
authored
Add 1.21.5 Support & Rework Code Structure (#11)
1 parent f70344b commit b8485a0

File tree

14 files changed

+564
-271
lines changed

14 files changed

+564
-271
lines changed

build.gradle.kts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@ plugins {
1616

1717
toolkitLoomHelper {
1818
useOneConfig {
19-
version = "1.0.0-alpha.70"
20-
loaderVersion = "1.1.0-alpha.44"
21-
19+
version = "1.0.0-alpha.153"
20+
loaderVersion = "1.1.0-alpha.49"
2221
usePolyMixin = true
23-
polyMixinVersion = "0.8.4+build.2"
24-
22+
polyMixinVersion = "0.8.4+build.6"
2523
applyLoaderTweaker = true
26-
2724
for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) {
2825
+module
2926
}
3027
}
28+
3129
useDevAuth("1.2.1")
32-
useMixinExtras("0.4.1")
30+
useMixinExtras("0.5.0")
3331

3432
// Turns off the server-side run configs, as we're building a client-sided mod.
3533
disableRunConfigs(GameSide.SERVER)
@@ -43,17 +41,4 @@ toolkitLoomHelper {
4341
// Configures the Mixin tweaker if we are building for Forge.
4442
useForgeMixin(modData.id)
4543
}
46-
}
47-
48-
dependencies {
49-
// Add (Legacy) Fabric API as dependencies (these are both optional but are particularly useful).
50-
if (mcData.isFabric) {
51-
if (mcData.isLegacyFabric) {
52-
// 1.8.9 - 1.13
53-
modImplementation("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${mcData.dependencies.legacyFabric.legacyFabricApiVersion}")
54-
} else {
55-
// 1.16.5+
56-
modImplementation("net.fabricmc.fabric-api:fabric-api:${mcData.dependencies.fabric.fabricApiVersion}")
57-
}
58-
}
59-
}
44+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ org.gradle.parallel=true
44
org.gradle.configureoncommand=true
55
org.gradle.parallel.threads=4
66
org.gradle.jvmargs=-Xmx2G
7+
loom.ignoreDependencyLoomVersionValidation=true
78

89
mod.group=org.polyfrost
910
mod.id=polyhitbox

root.gradle.kts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,29 @@ plugins {
33
}
44

55
preprocess {
6-
"1.8.9-forge"(10809, "srg")
6+
"1.21.8-fabric"(1_21_08, "yarn") {
7+
"1.21.5-fabric"(1_21_05, "yarn") {
8+
"1.21.4-fabric"(1_21_04, "yarn") {
9+
"1.21.1-fabric"(1_21_01, "yarn") {
10+
"1.20.4-fabric"(1_20_04, "yarn") {
11+
"1.20.1-fabric"(1_20_01, "yarn") {
12+
"1.16.5-fabric"(1_16_05, "yarn") {
13+
"1.16.5-forge"(1_16_05, "srg") {
14+
"1.12.2-forge"(1_12_02, "srg") {
15+
"1.12.2-fabric"(1_12_02, "yarn") {
16+
"1.8.9-fabric"(1_08_09, "yarn"){
17+
"1.8.9-forge"(1_08_09, "srg")
18+
}
19+
}
20+
}
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
strictExtraMappings.set(true)
731
}

settings.gradle.kts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,31 @@ pluginManagement {
2121
}
2222

2323
plugins {
24-
kotlin("jvm") version("2.0.0")
25-
id("dev.deftu.gradle.multiversion-root") version("2.35.0")
24+
kotlin("jvm") version ("2.2.10")
25+
id("dev.deftu.gradle.multiversion-root") version ("2.51.0")
2626
}
2727
}
2828

2929
val projectName: String = extra["mod.name"]?.toString()
3030
?: throw MissingPropertyException("mod.name has not been set.")
3131
rootProject.name = projectName
32+
3233
rootProject.buildFileName = "root.gradle.kts"
3334

3435
// Adds all of our build target versions to the classpath if we need to add version-specific code.
3536
listOf(
36-
"1.8.9-forge"
37+
"1.8.9-forge",
38+
"1.8.9-fabric",
39+
"1.12.2-forge",
40+
"1.12.2-fabric",
41+
"1.16.5-forge",
42+
"1.16.5-fabric",
43+
"1.20.1-fabric",
44+
"1.20.4-fabric",
45+
"1.21.1-fabric",
46+
"1.21.4-fabric",
47+
"1.21.5-fabric",
48+
"1.21.8-fabric"
3749
).forEach { version ->
3850
include(":$version")
3951
project(":$version").apply {
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package org.polyfrost.polyhitbox.mixin;
2+
3+
import dev.deftu.omnicore.api.client.OmniClient;
4+
import dev.deftu.omnicore.api.client.render.stack.OmniMatrixStack;
5+
import dev.deftu.omnicore.api.client.render.stack.OmniMatrixStacks;
6+
import dev.deftu.omnicore.api.data.vec.OmniVec3d;
7+
import dev.deftu.omnicore.api.entity.OmniEntities;
8+
import net.minecraft.client.render.entity.EntityRenderDispatcher;
9+
import net.minecraft.entity.Entity;
10+
import net.minecraft.entity.LivingEntity;
11+
import org.polyfrost.polyhitbox.HitboxRendererKt;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.injection.At;
14+
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
16+
17+
//#if MC >=1.21.5
18+
import net.minecraft.client.render.entity.state.EntityHitbox;
19+
//#endif
20+
21+
//#if MC >=1.16.5
22+
import net.minecraft.client.util.math.MatrixStack;
23+
import net.minecraft.client.render.VertexConsumer;
24+
import net.minecraft.client.render.VertexConsumerProvider;
25+
import org.spongepowered.asm.mixin.Unique;
26+
//#endif
27+
28+
@Mixin(EntityRenderDispatcher.class)
29+
public abstract class MixinRenderManager {
30+
//#if MC >=1.21.5
31+
@Unique
32+
private static ThreadLocal<Entity> polyhitbox$entity = ThreadLocal.withInitial(() -> null);
33+
//#endif
34+
35+
@Inject(
36+
//#if MC >=1.16.5
37+
method = "renderHitbox",
38+
//#else
39+
//$$ method = "renderDebugBoundingBox",
40+
//#endif
41+
at = @At("HEAD"),
42+
cancellable = true
43+
)
44+
//#if MC >=1.16.5
45+
private
46+
//#if MC >=1.20.1
47+
static
48+
//#endif
49+
void polyhitbox$customRendering(
50+
MatrixStack matrixStack,
51+
VertexConsumer vertexConsumer,
52+
//#if MC >=1.21.5
53+
EntityHitbox entityHitbox,
54+
//#else
55+
//$$ Entity entity,
56+
//$$ float tickDelta,
57+
//#if MC >=1.21.1
58+
//$$ float offsetX, float offsetY, float offsetZ,
59+
//#endif
60+
//#endif
61+
CallbackInfo ci
62+
) {
63+
//#else
64+
//$$ private void polyhitbox$customRendering(Entity entity, double offsetX, double offsetY, double offsetZ, float yaw, float tickDelta, CallbackInfo ci) {
65+
//#endif
66+
ci.cancel();
67+
OmniMatrixStack stack = OmniMatrixStacks.vanilla(
68+
//#if MC >=1.16.5
69+
matrixStack
70+
//#endif
71+
);
72+
73+
//#if MC >=1.21.5
74+
Entity entity = polyhitbox$entity.get();
75+
OmniVec3d offset = new OmniVec3d(entityHitbox.comp_3855(), entityHitbox.comp_3856(), entityHitbox.comp_3857());
76+
//#else
77+
//$$ OmniVec3d offset = OmniVec3d.ZERO;
78+
//#endif
79+
80+
HitboxRendererKt.renderHitbox(
81+
stack,
82+
offset,
83+
OmniEntities.getCurrentPos(entity),
84+
new OmniVec3d(entity.getRotationVector()),
85+
entity.getStandingEyeHeight(),
86+
entity instanceof LivingEntity,
87+
entity == OmniClient.get().targetedEntity,
88+
//#if MC >=1.16.5
89+
entity.getWidth(),
90+
//#else
91+
//$$ entity.width,
92+
//#endif
93+
entity.getTargetingMargin(),
94+
OmniEntities.getRenderBoundingBox(entity)
95+
);
96+
}
97+
98+
//#if MC >=1.21.5
99+
@com.llamalad7.mixinextras.injector.v2.WrapWithCondition(method = "renderHitboxes(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/entity/state/EntityHitboxAndView;Lnet/minecraft/client/render/VertexConsumer;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/VertexRendering;drawVector(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Lorg/joml/Vector3f;Lnet/minecraft/util/math/Vec3d;I)V"))
100+
private static boolean polyhitbox$removeViewRay(
101+
net.minecraft.client.util.math.MatrixStack matrixStack,
102+
net.minecraft.client.render.VertexConsumer vertexConsumer,
103+
org.joml.Vector3f vector3f,
104+
net.minecraft.util.math.Vec3d vec3d,
105+
int i
106+
) {
107+
return false;
108+
}
109+
110+
@Inject(method = "render(Lnet/minecraft/entity/Entity;DDDFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At("HEAD"))
111+
private static void polyhitbox$storeEntity(
112+
Entity entity,
113+
double x, double y, double z, float tickDelta,
114+
MatrixStack matrixStack,
115+
VertexConsumerProvider vertexConsumerProvider,
116+
int i,
117+
CallbackInfo ci
118+
) {
119+
polyhitbox$entity.set(entity);
120+
}
121+
//#endif
122+
}

0 commit comments

Comments
 (0)