Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void drawBackgroundAdditional(GUIContext context) {
var flight = client.level.getEntity(gun.flight());
Vec3 origin = flight == null ? gun.origin() : flight.getBoundingBox().getCenter();
var target = client.level.getEntity(gun.target());
Vec3 destination = target == null ? gun.destination() : target.getBoundingBox().getCenter();
Vec3 destination = gun.destination();
var laser = client.level.clip(new ClipContext(origin, destination, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, client.player));
Vec3 laserEnd = laser.getType() == HitResult.Type.MISS ? destination : laser.getLocation();
var points = new ObjectArrayList<Vec3>();
Expand All @@ -61,7 +61,8 @@ public void drawBackgroundAdditional(GUIContext context) {
if (!client.level.getChunkSource().hasChunk(blockPosition.getX() >> 4, blockPosition.getZ() >> 4)) break;
var block = client.level.clip(new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, client.player));
if (target != null) {
var hit = target.getBoundingBox().inflate(0.15).clip(from, block.getType() == HitResult.Type.MISS ? to : block.getLocation());
var predictedBounds = target.getBoundingBox().move(destination.subtract(target.getBoundingBox().getCenter()));
var hit = predictedBounds.inflate(0.15).clip(from, block.getType() == HitResult.Type.MISS ? to : block.getLocation());
if (hit.isPresent()) {
impact = hit.get();
points.add(impact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import com.fish_dan_.data_energistics.client.render.item.trident.DataTridentModel;
import com.fish_dan_.data_energistics.client.render.orbital.model.OrbitalModelPart;
import com.fish_dan_.data_energistics.client.render.research.ResearchStationRenderer;
import com.fish_dan_.data_energistics.client.weapon.platform.model.DroneAirframe;
import com.fish_dan_.data_energistics.client.weapon.platform.model.DroneItemModel;
import com.fish_dan_.data_energistics.client.weapon.platform.model.DroneWeapon;
import com.fish_dan_.data_energistics.common.data.DEStorageCells;

import appeng.api.client.StorageCellModels;
Expand All @@ -28,6 +31,8 @@ private ClientModelRegistrar() {}

public static void registerAdditionalModels(ModelEvent.RegisterAdditional event) {
FloatingGunProjectileRenderer.registerModels(event);
DroneAirframe.registerModels(event);
DroneWeapon.registerModels(event);
event.register(DataTridentModel.GEOMETRY);
StorageCellModels.models().values()
.forEach(model -> event.register(ModelResourceLocation.standalone(model)));
Expand All @@ -54,6 +59,7 @@ public static void registerAdditionalModels(ModelEvent.RegisterAdditional event)
}

public static void modifyBakingResult(ModelEvent.ModifyBakingResult event) {
DroneItemModel.install(event);
ModelResourceLocation compass = ModelResourceLocation.inventory(Data_Energistics.id("data_meteorite_compass"));
ModelResourceLocation base = ModelResourceLocation.standalone(Data_Energistics.id("item/data_meteorite_compass_base"));
ModelResourceLocation pointer = ModelResourceLocation.standalone(Data_Energistics.id("item/data_meteorite_compass_pointer"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,111 @@
package com.fish_dan_.data_energistics.client.weapon.platform;

import com.fish_dan_.data_energistics.Data_Energistics;
import com.fish_dan_.data_energistics.common.data.DEDataComponents;
import com.fish_dan_.data_energistics.common.data.DEItems;
import com.fish_dan_.data_energistics.common.research.item.ItemResearchUpgrades;
import com.fish_dan_.data_energistics.client.weapon.platform.animation.DroneFlightPose;
import com.fish_dan_.data_energistics.client.weapon.platform.animation.DroneWeaponPose;
import com.fish_dan_.data_energistics.client.weapon.platform.model.DroneAirframe;
import com.fish_dan_.data_energistics.client.weapon.platform.model.DroneAirframe.Pivot;
import com.fish_dan_.data_energistics.client.weapon.platform.model.DroneAirframe.Wing;
import com.fish_dan_.data_energistics.client.weapon.platform.model.DroneWeapon;
import com.fish_dan_.data_energistics.common.weapon.platform.flight.FloatingGunFlight;
import com.fish_dan_.data_energistics.common.weapon.platform.model.GunForm;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.util.Mth;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
import org.joml.Quaternionf;
import org.jspecify.annotations.NullMarked;

import java.util.EnumMap;

/** Renders the interpolated server flight position using the same baked model as the item and menu. */
/** Assembles the airframe, four six-blade rotors and the interchangeable belly weapon. */
@NullMarked
public final class FloatingGunRenderer extends EntityRenderer<FloatingGunFlight> {

private static final ResourceLocation TEXTURE = Data_Energistics.id("textures/item/weapon_platform/floating_gun/panel_mint.png");
private final EnumMap<GunForm, ItemStack> models = new EnumMap<>(GunForm.class);
private static final RenderType RENDER_TYPE = RenderType.entityCutout(InventoryMenu.BLOCK_ATLAS);

public FloatingGunRenderer(EntityRendererProvider.Context context) {
super(context);
for (GunForm form : GunForm.values()) {
ItemStack gun = new ItemStack(DEItems.DIGITAL_FLOATING_GUN.get());
if (form != GunForm.NORMAL) gun.set(DEDataComponents.RESEARCH_UPGRADES, new ItemResearchUpgrades(ObjectImmutableList.of(form.researchId)));
models.put(form, gun);
}
}

@Override
public void render(FloatingGunFlight entity, float yaw, float partialTick, PoseStack poses, MultiBufferSource buffers, int light) {
DroneAirframe airframe = DroneAirframe.forForm(entity.form());
Vec3 velocity = entity.flightVelocity(partialTick);
Vec3 acceleration = entity.flightAcceleration(partialTick);
DroneFlightPose flight = DroneFlightPose.sample(velocity.x, velocity.y, velocity.z,
acceleration.x, acceleration.y, acceleration.z, yaw, entity.flightTurnRate(partialTick));
double age = entity.tickCount + (double) partialTick;
VertexConsumer consumer = buffers.getBuffer(RENDER_TYPE);
poses.pushPose();
poses.translate(0, entity.getBbHeight() / 2 + Math.sin((entity.tickCount + partialTick) * 0.08 + entity.getId()) * 0.025, 0);
poses.translate(0, entity.getBbHeight() / 2 + Math.sin(age * .08 + entity.getId()) * .025, 0);
poses.mulPose(Axis.YP.rotationDegrees(180 - yaw));
Minecraft.getInstance().getItemRenderer().renderStatic(models.get(entity.form()), ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, poses, buffers, entity.level(), entity.getId());
poses.scale(.65f, .65f, .65f);
poses.mulPose(Axis.XP.rotationDegrees(flight.bodyPitch()));
poses.mulPose(Axis.ZP.rotationDegrees(flight.bodyRoll()));
poses.translate(-.5, -.5, -.5);
part(airframe.getBody(), poses, consumer);
int index = 0;
for (Wing wing : airframe.getWings()) {
poses.pushPose();
pivot(poses, wing.hinge(), 1);
poses.mulPose(new Quaternionf().rotationZYX(
(wing.rest().z() + flight.roll(wing.front(), wing.left())) * Mth.DEG_TO_RAD,
(wing.rest().y() + flight.sweep(wing.front(), wing.left())) * Mth.DEG_TO_RAD,
(wing.rest().x() + flight.pitch(wing.front(), wing.left())) * Mth.DEG_TO_RAD));
pivot(poses, wing.hinge(), -1);
part(wing.model(), poses, consumer);
poses.pushPose();
pivot(poses, wing.rotorPivot(), 1);
float phase = (float) ((age * 52.7 + entity.getId() * 39.0 + index++ * 23.0) % 360);
poses.mulPose(Axis.YP.rotationDegrees(wing.front() == wing.left() ? phase : -phase));
pivot(poses, wing.rotorPivot(), -1);
part(wing.rotor(), poses, consumer);
poses.popPose();
poses.popPose();
}
DroneWeapon weapon = DroneWeapon.forForm(entity.form());
part(weapon.getMount(), poses, consumer);
poses.pushPose();
if (weapon.isArticulated()) {
DroneWeaponPose aim = DroneWeaponPose.sample(yaw, entity.aimingYaw(partialTick), entity.getViewXRot(partialTick));
pivot(poses, weapon.getPivot(), 1);
// Keep the sight on its target while the hull banks; the mount still follows the hull.
poses.mulPose(Axis.ZP.rotationDegrees(-flight.bodyRoll()));
poses.mulPose(Axis.XP.rotationDegrees(-flight.bodyPitch()));
poses.mulPose(Axis.YP.rotationDegrees(aim.yaw()));
poses.mulPose(Axis.XP.rotationDegrees(aim.pitch()));
pivot(poses, weapon.getPivot(), -1);
}
part(weapon.getBarrel(), poses, consumer);
poses.popPose();
poses.popPose();
super.render(entity, yaw, partialTick, poses, buffers, light);
}

@Override
public ResourceLocation getTextureLocation(FloatingGunFlight entity) {
return TEXTURE;
return DroneAirframe.forForm(entity.form()).getTexture();
}

private static void pivot(PoseStack poses, Pivot pivot, int direction) {
poses.translate(direction * (pivot.x() / 16.0 + .5), direction * pivot.y() / 16.0,
direction * (pivot.z() / 16.0 + .5));
}

private static void part(ModelResourceLocation model, PoseStack poses, VertexConsumer consumer) {
Minecraft minecraft = Minecraft.getInstance();
minecraft.getItemRenderer().renderModelLists(minecraft.getModelManager().getModel(model), ItemStack.EMPTY,
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, poses, consumer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.fish_dan_.data_energistics.client.weapon.platform.animation;

/**
* Thrust-vector response to interpolated velocity and acceleration in world space.
* Angles are offsets from the authored wing pose, in degrees.
*/
public record DroneFlightPose(float forwardTilt, float sideTilt, float turnTilt, float liftTilt) {

public static DroneFlightPose sample(double dx, double dy, double dz, double ax, double ay, double az, float yaw, float turnRate) {
double radians = Math.toRadians(yaw);
double forward = dz * Math.cos(radians) - dx * Math.sin(radians);
double sideways = -dx * Math.cos(radians) - dz * Math.sin(radians);
double forwardAcceleration = az * Math.cos(radians) - ax * Math.sin(radians);
double sideAcceleration = -ax * Math.cos(radians) - az * Math.sin(radians);
return new DroneFlightPose(limit(forward * 32 + forwardAcceleration * 120, 24),
limit(sideways * 32 + sideAcceleration * 120, 22), limit(turnRate * .75, 9), limit(dy * 12 + ay * 35, 5));
}

public float bodyPitch() {
return -forwardTilt * .65f;
}

public float bodyRoll() {
return limit(-sideTilt * .65f - turnTilt * .45f, 18);
}

public float pitch(boolean front, boolean left) {
return -forwardTilt * .6f + (front ? -liftTilt : liftTilt) + (left ? turnTilt : -turnTilt) * .2f + (left ? -sideTilt : sideTilt) * .12f;
}

public float roll(boolean front, boolean left) {
return -sideTilt * .55f + (front ? turnTilt : -turnTilt) * .5f + (left ? -liftTilt : liftTilt) * .35f;
}

public float sweep(boolean front, boolean left) {
return (left ? -1 : 1) * (forwardTilt * .18f + liftTilt * .2f) + (front ? turnTilt : -turnTilt) * .25f + (front ? -sideTilt : sideTilt) * .08f;
}

private static float limit(double value, double maximum) {
return (float) Math.clamp(value, -maximum, maximum);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fish_dan_.data_energistics.client.weapon.platform.animation;

/** Model-local gimbal angles; stops keep the barrel below the airframe and inside its yaw travel. */
public record DroneWeaponPose(float yaw, float pitch) {

public static DroneWeaponPose sample(float hullYaw, float aimYaw, float aimPitch) {
float relative = (hullYaw - aimYaw) % 360;
if (relative >= 180) relative -= 360;
if (relative < -180) relative += 360;
return new DroneWeaponPose(Math.clamp(relative, -55, 55), -Math.clamp(aimPitch, -15, 75));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.fish_dan_.data_energistics.client.weapon.platform.model;

import com.fish_dan_.data_energistics.Data_Energistics;
import com.fish_dan_.data_energistics.common.weapon.platform.model.GunForm;

import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.client.event.ModelEvent;

import it.unimi.dsi.fastutil.objects.ObjectList;
import lombok.Getter;
import org.jspecify.annotations.NullMarked;

/** Client geometry and wing-root calibration from the two Blockbench source models. */
@NullMarked
@Getter
public enum DroneAirframe {

WHITE("white", ObjectList.of(
wing("white", "front_left", new Pivot(-4, 8.75f, -.1f), new Pivot(-9.5f, 8.7f, -2.1f),
new Rotation(-12, -7, -10), true, true),
wing("white", "front_right", new Pivot(4, 8.75f, -.1f), new Pivot(9.5f, 8.7f, -2.1f),
new Rotation(-12, 7, 10), true, false),
wing("white", "rear_left", new Pivot(-2.9f, 8.75f, 3.6f), new Pivot(-6.8f, 8.7f, 5.8f),
new Rotation(12, 9, 14), false, true),
wing("white", "rear_right", new Pivot(2.9f, 8.75f, 3.6f), new Pivot(6.8f, 8.7f, 5.8f),
new Rotation(12, -9, -14), false, false))),
BLACK("black", ObjectList.of(
wing("black", "front_left", new Pivot(-2.9f, 8.75f, -3.6f), new Pivot(-6.8f, 8.7f, -5.8f),
new Rotation(-4, -7, 12), true, true),
wing("black", "front_right", new Pivot(2.9f, 8.75f, -3.6f), new Pivot(6.8f, 8.7f, -5.8f),
new Rotation(-4, 7, -12), true, false),
wing("black", "rear_left", new Pivot(-3.35f, 8.75f, 1.8f), new Pivot(-9.5f, 8.7f, 2.1f),
new Rotation(0, 5, 14), false, true),
wing("black", "rear_right", new Pivot(3.35f, 8.75f, 1.8f), new Pivot(9.5f, 8.7f, 2.1f),
new Rotation(0, -5, -14), false, false)));

private final ModelResourceLocation body;
private final ModelResourceLocation assembled;
private final ResourceLocation texture;
private final ObjectList<Wing> wings;

DroneAirframe(String variant, ObjectList<Wing> wings) {
body = model(variant, "body");
assembled = model(variant, "assembled");
texture = Data_Energistics.id("textures/item/weapon_platform/floating_gun/drones/" + variant + ".png");
this.wings = wings;
}

public static DroneAirframe forForm(GunForm form) {
return switch (form) {
case NORMAL, MEDICAL -> WHITE;
case SNIPER, PLASMA, GRENADE -> BLACK;
};
}

public static void registerModels(ModelEvent.RegisterAdditional event) {
for (DroneAirframe airframe : values()) {
event.register(airframe.body);
event.register(airframe.assembled);
for (Wing wing : airframe.wings) {
event.register(wing.model);
event.register(wing.rotor);
}
}
}

private static Wing wing(String variant, String section, Pivot hinge, Pivot rotorPivot,
Rotation rest, boolean front, boolean left) {
return new Wing(model(variant, "wing_" + section), model(variant, "rotor_" + section),
hinge, rotorPivot, rest, front, left);
}

private static ModelResourceLocation model(String variant, String part) {
return ModelResourceLocation.standalone(
Data_Energistics.id("item/weapon_platform/drones/" + variant + "/" + part));
}

/** An unposed wing and its child rotor; pivots use Blockbench model units. */
public record Wing(ModelResourceLocation model, ModelResourceLocation rotor, Pivot hinge,
Pivot rotorPivot, Rotation rest, boolean front, boolean left) {}

/** Absolute coordinates before the OBJ loader's half-block X/Z centering offset. */
public record Pivot(float x, float y, float z) {}

/** Degrees in Blockbench's ZYX Euler order. */
public record Rotation(float x, float y, float z) {}
}
Loading
Loading