使用Molang渲染RPG
This commit is contained in:
parent
89ea21aa9e
commit
fb7ef5d258
5 changed files with 39 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.client.model.item;
|
package com.atsuishio.superbwarfare.client.model.item;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.client.molang.MolangVariable;
|
import com.atsuishio.superbwarfare.client.molang.MolangVariable;
|
||||||
|
import com.atsuishio.superbwarfare.data.gun.GunData;
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import software.bernie.geckolib.animatable.GeoAnimatable;
|
import software.bernie.geckolib.animatable.GeoAnimatable;
|
||||||
|
@ -9,20 +10,38 @@ import software.bernie.geckolib.loading.math.MathParser;
|
||||||
import software.bernie.geckolib.loading.math.MolangQueries;
|
import software.bernie.geckolib.loading.math.MolangQueries;
|
||||||
import software.bernie.geckolib.model.GeoModel;
|
import software.bernie.geckolib.model.GeoModel;
|
||||||
|
|
||||||
|
import java.util.function.DoubleSupplier;
|
||||||
|
|
||||||
public abstract class CustomGunModel<T extends GunItem & GeoAnimatable> extends GeoModel<T> {
|
public abstract class CustomGunModel<T extends GunItem & GeoAnimatable> extends GeoModel<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyMolangQueries(AnimationState<T> animationState, double animTime) {
|
public void applyMolangQueries(AnimationState<T> animationState, double animTime) {
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getInstance();
|
||||||
|
|
||||||
MathParser.setVariable(MolangQueries.LIFE_TIME, () -> animTime / 20d);
|
set(MolangQueries.LIFE_TIME, () -> animTime / 20d);
|
||||||
|
|
||||||
if (mc.level != null) {
|
if (mc.level != null) {
|
||||||
MathParser.setVariable(MolangQueries.ACTOR_COUNT, mc.level::getEntityCount);
|
set(MolangQueries.ACTOR_COUNT, mc.level::getEntityCount);
|
||||||
MathParser.setVariable(MolangQueries.TIME_OF_DAY, () -> mc.level.getDayTime() / 24000f);
|
set(MolangQueries.TIME_OF_DAY, () -> mc.level.getDayTime() / 24000f);
|
||||||
MathParser.setVariable(MolangQueries.MOON_PHASE, mc.level::getMoonPhase);
|
set(MolangQueries.MOON_PHASE, mc.level::getMoonPhase);
|
||||||
}
|
}
|
||||||
|
|
||||||
MathParser.setVariable(MolangVariable.SBW_SYSTEM_TIME, System::currentTimeMillis);
|
set(MolangVariable.SBW_SYSTEM_TIME, System::currentTimeMillis);
|
||||||
|
|
||||||
|
// GunData
|
||||||
|
|
||||||
|
var player = mc.player;
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
var stack = player.getMainHandItem();
|
||||||
|
if (!(stack.getItem() instanceof GunItem)) return;
|
||||||
|
|
||||||
|
var data = GunData.from(stack);
|
||||||
|
|
||||||
|
set(MolangVariable.SBW_IS_EMPTY, () -> data.isEmpty.get() ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void set(String key, DoubleSupplier value) {
|
||||||
|
MathParser.setVariable(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,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.model.GeoModel;
|
|
||||||
|
|
||||||
public class RpgItemModel extends GeoModel<RpgItem> {
|
public class RpgItemModel extends CustomGunModel<RpgItem> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getAnimationResource(RpgItem animatable) {
|
public ResourceLocation getAnimationResource(RpgItem animatable) {
|
||||||
|
|
|
@ -8,9 +8,11 @@ import java.util.function.DoubleSupplier;
|
||||||
public class MolangVariable {
|
public class MolangVariable {
|
||||||
|
|
||||||
public static final String SBW_SYSTEM_TIME = "query.sbw_system_time";
|
public static final String SBW_SYSTEM_TIME = "query.sbw_system_time";
|
||||||
|
public static final String SBW_IS_EMPTY = "query.sbw_is_empty";
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
register(SBW_SYSTEM_TIME, () -> 0);
|
register(SBW_SYSTEM_TIME, () -> 0);
|
||||||
|
register(SBW_IS_EMPTY, () -> 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void register(String name, DoubleSupplier supplier) {
|
private static void register(String name, DoubleSupplier supplier) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.client.renderer.gun;
|
||||||
import com.atsuishio.superbwarfare.client.AnimationHelper;
|
import com.atsuishio.superbwarfare.client.AnimationHelper;
|
||||||
import com.atsuishio.superbwarfare.client.model.item.RpgItemModel;
|
import com.atsuishio.superbwarfare.client.model.item.RpgItemModel;
|
||||||
import com.atsuishio.superbwarfare.client.renderer.CustomGunRenderer;
|
import com.atsuishio.superbwarfare.client.renderer.CustomGunRenderer;
|
||||||
import com.atsuishio.superbwarfare.data.gun.GunData;
|
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
|
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
@ -37,10 +36,6 @@ public class RpgItemRenderer extends CustomGunRenderer<RpgItem> {
|
||||||
ItemStack itemStack = player.getMainHandItem();
|
ItemStack itemStack = player.getMainHandItem();
|
||||||
if (!(itemStack.getItem() instanceof GunItem)) return;
|
if (!(itemStack.getItem() instanceof GunItem)) return;
|
||||||
|
|
||||||
if (name.equals("Rockets")) {
|
|
||||||
bone.setHidden(GunData.from(itemStack).isEmpty.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0, 0.625, 0.7);
|
AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0, 0.625, 0.7);
|
||||||
|
|
||||||
if (renderingArms) {
|
if (renderingArms) {
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"bones": {
|
"bones": {
|
||||||
"Rockets": {
|
"Rockets": {
|
||||||
"rotation": [0, 0, 0],
|
"rotation": [0, 0, 0],
|
||||||
"position": [0, 0, 0]
|
"position": [0, 0, 0],
|
||||||
|
"scale": "query.sbw_is_empty ? 0 : 1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -33,7 +34,8 @@
|
||||||
},
|
},
|
||||||
"Rockets": {
|
"Rockets": {
|
||||||
"rotation": [0, 0, 0],
|
"rotation": [0, 0, 0],
|
||||||
"position": [0, 0, 0]
|
"position": [0, 0, 0],
|
||||||
|
"scale": "query.sbw_is_empty ? 0 : 1"
|
||||||
},
|
},
|
||||||
"camera": {
|
"camera": {
|
||||||
"rotation": {
|
"rotation": {
|
||||||
|
@ -68,7 +70,8 @@
|
||||||
},
|
},
|
||||||
"Rockets": {
|
"Rockets": {
|
||||||
"rotation": [0, 0, 0],
|
"rotation": [0, 0, 0],
|
||||||
"position": [0, 0, 0]
|
"position": [0, 0, 0],
|
||||||
|
"scale": "query.sbw_is_empty ? 0 : 1"
|
||||||
},
|
},
|
||||||
"Lefthand": {
|
"Lefthand": {
|
||||||
"rotation": [-26.58235, 45.45121, -16.52546],
|
"rotation": [-26.58235, 45.45121, -16.52546],
|
||||||
|
@ -86,7 +89,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"animation.rpg.fire": {
|
"animation.rpg.fire": {
|
||||||
"animation_length": 0.1
|
"animation_length": 0.1,
|
||||||
|
"bones": {
|
||||||
|
"Rockets": {
|
||||||
|
"scale": "query.sbw_is_empty ? 0 : 1"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"animation.rpg.reload": {
|
"animation.rpg.reload": {
|
||||||
"loop": "hold_on_last_frame",
|
"loop": "hold_on_last_frame",
|
||||||
|
|
Loading…
Add table
Reference in a new issue