添加自定义gun model

This commit is contained in:
17146 2025-05-19 01:08:08 +08:00 committed by Light_Quanta
parent c0f92a71e4
commit f0a5454b14
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 148 additions and 110 deletions

View file

@ -0,0 +1,28 @@
package com.atsuishio.superbwarfare.client.model.item;
import com.atsuishio.superbwarfare.client.molang.MolangVariable;
import com.atsuishio.superbwarfare.item.gun.GunItem;
import net.minecraft.client.Minecraft;
import software.bernie.geckolib.animatable.GeoAnimatable;
import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.loading.math.MathParser;
import software.bernie.geckolib.loading.math.MolangQueries;
import software.bernie.geckolib.model.GeoModel;
public abstract class CustomGunModel<T extends GunItem & GeoAnimatable> extends GeoModel<T> {
@Override
public void applyMolangQueries(AnimationState<T> animationState, double animTime) {
Minecraft mc = Minecraft.getInstance();
MathParser.setVariable(MolangQueries.LIFE_TIME, () -> animTime / 20d);
if (mc.level != null) {
MathParser.setVariable(MolangQueries.ACTOR_COUNT, mc.level::getEntityCount);
MathParser.setVariable(MolangQueries.TIME_OF_DAY, () -> mc.level.getDayTime() / 24000f);
MathParser.setVariable(MolangQueries.MOON_PHASE, mc.level::getMoonPhase);
}
MathParser.setVariable(MolangVariable.SBW_SYSTEM_TIME, System::currentTimeMillis);
}
}

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.client.model.item;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.client.renderer.molang.MolangVariable;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.item.gun.rifle.InsidiousItem; import com.atsuishio.superbwarfare.item.gun.rifle.InsidiousItem;
@ -14,10 +13,8 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import software.bernie.geckolib.animation.AnimationState; import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.cache.object.GeoBone; import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.loading.math.MathParser;
import software.bernie.geckolib.model.GeoModel;
public class InsidiousItemModel extends GeoModel<InsidiousItem> { public class InsidiousItemModel extends CustomGunModel<InsidiousItem> {
public static float fireRotY = 0f; public static float fireRotY = 0f;
public static float fireRotZ = 0f; public static float fireRotZ = 0f;
@ -91,10 +88,4 @@ public class InsidiousItemModel extends GeoModel<InsidiousItem> {
AnimationHelper.handleReloadShakeAnimation(stack, main, camera, numR, numP); AnimationHelper.handleReloadShakeAnimation(stack, main, camera, numR, numP);
ClientEventHandler.handleReloadShake(Mth.RAD_TO_DEG * camera.getRotX(), Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ()); ClientEventHandler.handleReloadShake(Mth.RAD_TO_DEG * camera.getRotX(), Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ());
} }
@Override
public void applyMolangQueries(AnimationState<InsidiousItem> animationState, double animTime) {
super.applyMolangQueries(animationState, animTime);
MathParser.setVariable(MolangVariable.SBW_SYSTEM_TIME, System::currentTimeMillis);
}
} }

View file

@ -0,0 +1,19 @@
package com.atsuishio.superbwarfare.client.molang;
import software.bernie.geckolib.loading.math.MathParser;
import software.bernie.geckolib.loading.math.value.Variable;
import java.util.function.DoubleSupplier;
public class MolangVariable {
public static final String SBW_SYSTEM_TIME = "query.sbw_system_time";
public static void register() {
register(SBW_SYSTEM_TIME, () -> 0);
}
private static void register(String name, DoubleSupplier supplier) {
MathParser.registerVariable(new Variable(name, supplier));
}
}

View file

@ -5,10 +5,10 @@
"animation_length": 1, "animation_length": 1,
"bones": { "bones": {
"rot1": { "rot1": {
"rotation": [0, 0, "(sbw.system_time % 36000000) / 400 / 2 / math.pi * 360"] "rotation": [0, 0, "(query.sbw_system_time % 36000000) / 1600 / math.pi * 360"]
}, },
"rot2": { "rot2": {
"rotation": [0, 0, "-(sbw.system_time % 36000000) / 400 / 2 / math.pi * 360"] "rotation": [0, 0, "(query.sbw_system_time % 36000000) / 1600 / math.pi * (-360)"]
} }
} }
}, },
@ -308,34 +308,34 @@
"Lefthand": { "Lefthand": {
"rotation": { "rotation": {
"0.0": [0, 0, 0], "0.0": [0, 0, 0],
"0.0833": [-3.1936, 24.51049, 7.5871], "0.0667": [-3.1936, 24.51049, 7.5871],
"0.2083": [-3.14008, 19.39916, 11.32393], "0.2": [-3.14008, 19.39916, 11.32393],
"0.2917": [-4.46292, 0.94838, 16.96183], "0.2917": [-4.46292, 0.94838, 16.96183],
"0.4583": [-4.46292, 0.94838, 16.96183], "0.4583": [-4.46292, 0.94838, 16.96183],
"0.7083": [-4.46292, 0.94838, 16.96183], "0.7083": [-4.46292, 0.94838, 16.96183],
"0.8333": [-28.33435, -12.61568, 45.95484], "0.8167": [-28.33435, -12.61568, 45.95484],
"1.5417": [-28.33435, -12.61568, 45.95484], "1.5417": [-28.33435, -12.61568, 45.95484],
"1.75": [-15.82573, 15.60063, 31.96328], "1.75": [-15.82573, 15.60063, 31.96328],
"1.7917": [-19.88703, 0.29301, 34.55901], "1.8": [-19.88703, 0.29301, 34.55901],
"1.9167": [-18.4573, 3.88617, 32.29314], "1.9333": [-18.4573, 3.88617, 32.29314],
"2.0417": [0, 0, 7], "2.0417": [0, 0, 7],
"2.125": [0, 0, 0] "2.1083": [0, 0, 0]
}, },
"position": { "position": {
"0.0": [0, 0, 0], "0.0": [0, 0, 0],
"0.0833": [0, -0.8, 0], "0.0667": [0, -0.8, 0],
"0.2083": [-0.09, -3.36, 9.03], "0.2": [-0.09, -3.36, 9.03],
"0.2917": [-0.15, -2.75, 16], "0.2917": [-0.15, -2.75, 16],
"0.4583": [-0.15, -2.75, 16], "0.4583": [-0.15, -2.75, 16],
"0.7083": [-0.15, -2.75, 16], "0.7083": [-0.15, -2.75, 16],
"0.8333": [-0.55, -2.75, 17.65], "0.8167": [-0.55, -2.75, 17.65],
"1.5417": [-0.55, -2.75, 17.65], "1.5417": [-0.55, -2.75, 17.65],
"1.625": [-1, -3.59, 15.87], "1.6417": [-1, -3.59, 15.87],
"1.75": [-0.55, -7.7, 14.1], "1.75": [-0.55, -7.7, 14.1],
"1.7917": [-0.55, -3.35, 16.25], "1.8": [-0.55, -3.35, 16.25],
"1.9167": [-0.55, -5.5, 14.15], "1.9333": [-0.55, -5.5, 14.15],
"2.0417": [0, -1, 2], "2.0417": [0, -1, 2],
"2.125": [0, 0, 0] "2.1083": [0, 0, 0]
} }
}, },
"camera": { "camera": {
@ -487,10 +487,77 @@
} }
}, },
"rot1": { "rot1": {
"rotation": [0, 0, "(sbw.system_time % 36000000) / 400 / 2 / math.pi * 360"] "rotation": [0, 0, "(query.sbw_system_time % 36000000) / 1600 / 3 / math.pi * 360"]
}, },
"rot2": { "rot2": {
"rotation": [0, 0, "-(sbw.system_time % 36000000) / 400 / 2 / math.pi * 360"] "rotation": [0, 0, "(query.sbw_system_time % 36000000) / 1600 / 3 / math.pi * (-360)"]
}
}
},
"animation.insidious.run": {
"loop": true,
"animation_length": 0.8,
"bones": {
"0": {
"rotation": {
"0.0": {
"post": [-19.82442, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
},
"0.2": {
"post": [-23.65942, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
},
"0.4": {
"post": [-19.82442, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
},
"0.6": {
"post": [-15.98942, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
},
"0.8": {
"post": [-19.82442, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
}
},
"position": {
"0.0": {
"post": [6.85, -3.45, 0],
"lerp_mode": "catmullrom"
},
"0.2": {
"post": [4.8, -2.45, 0],
"lerp_mode": "catmullrom"
},
"0.4": {
"post": [3.1, -3.45, 0],
"lerp_mode": "catmullrom"
},
"0.6": {
"post": [4.35, -2.45, 0],
"lerp_mode": "catmullrom"
},
"0.8": {
"post": [6.85, -3.45, 0],
"lerp_mode": "catmullrom"
}
}
},
"camera": {
"rotation": {
"0.0": [-0.3, -0.3, 0.3],
"0.2": [0.3, 0, -0.3],
"0.4": [-0.3, 0.3, 0.3],
"0.6": [0.3, 0, -0.3],
"0.8": [-0.3, -0.3, 0.3]
}
},
"rot1": {
"rotation": [0, 0, "(query.sbw_system_time % 36000000) / 1600 / 0.8 / math.pi * 360"]
},
"rot2": {
"rotation": [0, 0, "(query.sbw_system_time % 36000000) / 1600 / 0.8 / math.pi * (-360)"]
} }
} }
}, },
@ -559,77 +626,10 @@
} }
}, },
"rot1": { "rot1": {
"rotation": [0, 0, "(sbw.system_time % 36000000) / 400 / 2 / math.pi * 360"] "rotation": [0, 0, "(query.sbw_system_time % 36000000) / 1600 / 0.7 / math.pi * 360"]
}, },
"rot2": { "rot2": {
"rotation": [0, 0, "-(sbw.system_time % 36000000) / 400 / 2 / math.pi * 360"] "rotation": [0, 0, "(query.sbw_system_time % 36000000) / 1600 / 0.7 / math.pi * (-360)"]
}
}
},
"animation.insidious.run": {
"loop": true,
"animation_length": 1,
"bones": {
"0": {
"rotation": {
"0.0": {
"post": [-19.82442, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
},
"0.2": {
"post": [-23.65942, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
},
"0.4": {
"post": [-19.82442, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
},
"0.6": {
"post": [-15.98942, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
},
"0.8": {
"post": [-19.82442, -57.81517, 38.62375],
"lerp_mode": "catmullrom"
}
},
"position": {
"0.0": {
"post": [6.85, -3.45, 0],
"lerp_mode": "catmullrom"
},
"0.2": {
"post": [4.8, -2.45, 0],
"lerp_mode": "catmullrom"
},
"0.4": {
"post": [3.1, -3.45, 0],
"lerp_mode": "catmullrom"
},
"0.6": {
"post": [4.35, -2.45, 0],
"lerp_mode": "catmullrom"
},
"0.8": {
"post": [6.85, -3.45, 0],
"lerp_mode": "catmullrom"
}
}
},
"camera": {
"rotation": {
"0.0": [-0.3, -0.3, 0.3],
"0.2": [0.3, 0, -0.3],
"0.4": [-0.3, 0.3, 0.3],
"0.6": [0.3, 0, -0.3],
"0.8": [-0.3, -0.3, 0.3]
}
},
"rot1": {
"rotation": [0, 0, "(sbw.system_time % 36000000) / 400 / 2 / math.pi * 360"]
},
"rot2": {
"rotation": [0, 0, "-(sbw.system_time % 36000000) / 400 / 2 / math.pi * 360"]
} }
} }
} }

View file

@ -38,7 +38,7 @@ side = "BOTH"
[[dependencies.superbwarfare]] [[dependencies.superbwarfare]]
modId = "geckolib" modId = "geckolib"
type = "required" type = "required"
versionRange = "[4.7.1.2,)" versionRange = "[4.4.6,)"
ordering = "NONE" ordering = "NONE"
side = "BOTH" side = "BOTH"