尝试实现夕雾花渲染分离
This commit is contained in:
parent
ba9301f702
commit
21faa4c0f1
4 changed files with 79 additions and 56 deletions
|
@ -31,4 +31,24 @@ public class ItemModelHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void hideAllAttachments(GeoBone bone, String name) {
|
||||
splitAndHideBone(bone, name, "Scope");
|
||||
splitAndHideBone(bone, name, "Magazine");
|
||||
splitAndHideBone(bone, name, "Barrel");
|
||||
splitAndHideBone(bone, name, "Stock");
|
||||
splitAndHideBone(bone, name, "Grip");
|
||||
}
|
||||
|
||||
private static void splitAndHideBone(GeoBone bone, String boneName, String tagName) {
|
||||
try {
|
||||
if (boneName.startsWith(tagName)) {
|
||||
String[] parts = boneName.split("(?<=\\D)(?=\\d)");
|
||||
if (parts.length == 2) {
|
||||
int index = Integer.parseInt(parts[1]);
|
||||
bone.setHidden(index != 0);
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
|||
import com.atsuishio.superbwarfare.data.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.data.gun.value.AttachmentType;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.handgun.Trachelium;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -16,11 +15,10 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import software.bernie.geckolib.animation.AnimationState;
|
||||
import software.bernie.geckolib.cache.object.GeoBone;
|
||||
import software.bernie.geckolib.model.GeoModel;
|
||||
|
||||
import static com.atsuishio.superbwarfare.event.ClientEventHandler.isProne;
|
||||
|
||||
public class TracheliumItemModel extends GeoModel<Trachelium> {
|
||||
public class TracheliumItemModel extends CustomGunModel<Trachelium> {
|
||||
|
||||
public static float posYAlt = -0.83f;
|
||||
public static float scaleZAlt = 0.8f;
|
||||
|
@ -46,7 +44,12 @@ public class TracheliumItemModel extends GeoModel<Trachelium> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setCustomAnimations(Trachelium animatable, long instanceId, AnimationState animationState) {
|
||||
public void setCustomAnimations(Trachelium animatable, long instanceId, AnimationState<Trachelium> animationState) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (shouldCancelRender(stack, animationState)) return;
|
||||
|
||||
GeoBone gun = getAnimationProcessor().getBone("bone");
|
||||
GeoBone hammer = getAnimationProcessor().getBone("jichui");
|
||||
GeoBone lun = getAnimationProcessor().getBone("lun");
|
||||
|
@ -57,11 +60,6 @@ public class TracheliumItemModel extends GeoModel<Trachelium> {
|
|||
GeoBone main = getAnimationProcessor().getBone("0");
|
||||
GeoBone scope2 = getAnimationProcessor().getBone("Scope2");
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
|
||||
float times = 0.4f * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8);
|
||||
double zt = ClientEventHandler.zoomTime;
|
||||
double zp = ClientEventHandler.zoomPos;
|
||||
|
@ -81,28 +79,24 @@ public class TracheliumItemModel extends GeoModel<Trachelium> {
|
|||
posZAlt = Mth.lerp(times, posZAlt, NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 7.5f : 13.7f);
|
||||
|
||||
float posY = switch (scopeType) {
|
||||
case 0 -> 1.1f;
|
||||
case 0, 3 -> 1.1f;
|
||||
case 1 -> -0.18f;
|
||||
case 2 -> posYAlt;
|
||||
case 3 -> 1.1f;
|
||||
default -> 0f;
|
||||
};
|
||||
float scaleZ = switch (scopeType) {
|
||||
case 0 -> 0.2f;
|
||||
case 0, 3 -> 0.2f;
|
||||
case 1 -> 0.6f;
|
||||
case 2 -> scaleZAlt;
|
||||
case 3 -> 0.2f;
|
||||
default -> 0f;
|
||||
};
|
||||
float posZ = switch (scopeType) {
|
||||
case 0 -> 1f;
|
||||
case 0, 3 -> 1f;
|
||||
case 1 -> 6f;
|
||||
case 2 -> posZAlt;
|
||||
case 3 -> 1f;
|
||||
default -> 0f;
|
||||
};
|
||||
|
||||
|
||||
float posZAlt = stockType == 2 ? 1 : 0;
|
||||
|
||||
gun.setPosX((float) (3.48f * zp));
|
||||
|
|
|
@ -16,6 +16,7 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.cache.object.GeoBone;
|
||||
|
||||
public class TracheliumItemRenderer extends CustomGunRenderer<Trachelium> {
|
||||
|
@ -39,7 +40,24 @@ public class TracheliumItemRenderer extends CustomGunRenderer<Trachelium> {
|
|||
var player = mc.player;
|
||||
if (player == null) return;
|
||||
ItemStack itemStack = player.getMainHandItem();
|
||||
if (!(itemStack.getItem() instanceof GunItem)) return;
|
||||
|
||||
if (itemStack.getItem() instanceof GunItem && GeoItem.getId(itemStack) == this.getInstanceId(animatable)) {
|
||||
AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0, 0.734375, 0.5);
|
||||
ItemModelHelper.handleGunAttachments(bone, itemStack, name);
|
||||
|
||||
int scopeType = GunData.from(itemStack).attachment.get(AttachmentType.SCOPE);
|
||||
|
||||
switch (scopeType) {
|
||||
case 1 ->
|
||||
AnimationHelper.handleZoomCrossHair(currentBuffer, renderType, name, stack, bone, buffer, 0, 0.3, 30, 1.2f, 255, 0, 0, 255, "dot", false);
|
||||
case 2 -> {
|
||||
if (NBTTool.getTag(itemStack).getBoolean("ScopeAlt")) {
|
||||
AnimationHelper.handleZoomCrossHair(currentBuffer, renderType, name, stack, bone, buffer, 0, 0.36, 30, 0.18f, 255, 0, 0, 255, "delta", false);
|
||||
} else {
|
||||
AnimationHelper.handleZoomCrossHair(currentBuffer, renderType, name, stack, bone, buffer, 0, 0.294, 13, 0.87f, 255, 0, 0, 255, "hamr", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (name.equals("humu")) {
|
||||
bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 0 && GunData.from(itemStack).attachment.get(AttachmentType.GRIP) == 0);
|
||||
|
@ -57,31 +75,18 @@ public class TracheliumItemRenderer extends CustomGunRenderer<Trachelium> {
|
|||
bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.GRIP) == 0);
|
||||
}
|
||||
|
||||
|
||||
if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && !NBTTool.getTag(itemStack).getBoolean("ScopeAlt") && (name.equals("hidden"))) {
|
||||
bone.setHidden(ClientEventHandler.zoomPos > 0.7 && ClientEventHandler.zoom);
|
||||
}
|
||||
|
||||
int scopeType = GunData.from(itemStack).attachment.get(AttachmentType.SCOPE);
|
||||
|
||||
switch (scopeType) {
|
||||
case 1 ->
|
||||
AnimationHelper.handleZoomCrossHair(currentBuffer, renderType, name, stack, bone, buffer, 0, 0.3, 30, 1.2f, 255, 0, 0, 255, "dot", false);
|
||||
case 2 -> {
|
||||
if (NBTTool.getTag(itemStack).getBoolean("ScopeAlt")) {
|
||||
AnimationHelper.handleZoomCrossHair(currentBuffer, renderType, name, stack, bone, buffer, 0, 0.36, 30, 0.18f, 255, 0, 0, 255, "delta", false);
|
||||
} else {
|
||||
AnimationHelper.handleZoomCrossHair(currentBuffer, renderType, name, stack, bone, buffer, 0, 0.294, 13, 0.87f, 255, 0, 0, 255, "hamr", true);
|
||||
ItemModelHelper.hideAllAttachments(bone, name);
|
||||
if (name.equals("humu") || name.equals("qianzhunxing1") || name.equals("railup") || name.equals("raildown")) {
|
||||
bone.setHidden(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ItemModelHelper.handleGunAttachments(bone, itemStack, name);
|
||||
|
||||
AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0, 0.734375, 0.5);
|
||||
|
||||
if (renderingArms) {
|
||||
AnimationHelper.renderArms(player, this.transformType, stack, name, bone, this.currentBuffer, type, packedLightIn, true);
|
||||
AnimationHelper.renderArms(player, this.renderPerspective, stack, name, bone, buffer, type, packedLightIn, true);
|
||||
}
|
||||
super.renderRecursively(stack, animatable, bone, type, buffer, bufferIn, isReRender, partialTick, packedLightIn, packedOverlayIn, color);
|
||||
}
|
||||
|
|
|
@ -16,12 +16,10 @@ import net.minecraft.network.chat.Component;
|
|||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import software.bernie.geckolib.animation.*;
|
||||
import software.bernie.geckolib.constant.DataTickets;
|
||||
import software.bernie.geckolib.renderer.GeoItemRenderer;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
@ -50,6 +48,8 @@ public class Trachelium extends GunItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
if (event.getData(DataTickets.ITEM_RENDER_PERSPECTIVE) != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND)
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.trachelium.idle"));
|
||||
|
||||
var data = GunData.from(stack);
|
||||
boolean stock = data.attachment.get(AttachmentType.STOCK) == 2;
|
||||
|
@ -91,8 +91,10 @@ public class Trachelium extends GunItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
var data = GunData.from(stack);
|
||||
if (event.getData(DataTickets.ITEM_RENDER_PERSPECTIVE) != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND)
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.trachelium.idle"));
|
||||
|
||||
var data = GunData.from(stack);
|
||||
boolean stock = data.attachment.get(AttachmentType.STOCK) == 2;
|
||||
boolean grip = data.attachment.get(AttachmentType.GRIP) > 0 || data.attachment.get(AttachmentType.SCOPE) > 0;
|
||||
|
||||
|
@ -180,6 +182,8 @@ public class Trachelium extends GunItem {
|
|||
if (player == null) return PlayState.STOP;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP;
|
||||
if (event.getData(DataTickets.ITEM_RENDER_PERSPECTIVE) != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND)
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.trachelium.idle"));
|
||||
|
||||
if (ClickHandler.isEditing) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.trachelium.edit"));
|
||||
|
|
Loading…
Add table
Reference in a new issue