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
14 changes: 14 additions & 0 deletions src/main/java/dev/amble/ait/AITMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
Expand Down Expand Up @@ -64,6 +65,7 @@
import dev.amble.ait.core.loot.SetBlueprintLootFunction;
import dev.amble.ait.core.sounds.flight.FlightSoundRegistry;
import dev.amble.ait.core.sounds.travel.TravelSoundRegistry;
import dev.amble.ait.core.tardis.ServerTardis;
import dev.amble.ait.core.tardis.animation.v2.blockbench.BlockbenchParser;
import dev.amble.ait.core.tardis.animation.v2.datapack.TardisAnimationRegistry;
import dev.amble.ait.core.tardis.control.sound.ControlSoundRegistry;
Expand Down Expand Up @@ -306,6 +308,18 @@ public void onInitialize() {
});
});


// Rahhhh this is just to catch the player from logging out with the TARDIS in RWF
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
ServerPlayerEntity serverPlayer = handler.player;
if (serverPlayer.getVehicle() instanceof FlightTardisEntity flight) {
if (!flight.isLinked()) return;
ServerTardis tardis = flight.tardis().get().asServer();

tardis.flight().exitFlight(serverPlayer);
}
});

LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
if (source.isBuiltin()
&& (id.equals(LootTables.NETHER_BRIDGE_CHEST) || id.equals(LootTables.DESERT_PYRAMID_CHEST)
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/dev/amble/ait/client/AITModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static dev.amble.ait.AITMod.*;
import static dev.amble.ait.core.AITItems.isUnlockedOnThisDay;
import static dev.amble.ait.core.entities.FlightTardisEntity.PLAY_FLIGHT_SOUND;
import static dev.amble.ait.core.entities.FlightTardisEntity.STOP_FLIGHT_SOUND;
import static dev.amble.ait.core.item.PersonalityMatrixItem.colorToInt;

import java.util.ArrayList;
Expand Down Expand Up @@ -35,6 +37,7 @@
import net.minecraft.client.render.entity.model.SinglePartEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
Expand Down Expand Up @@ -78,6 +81,7 @@
import dev.amble.ait.client.screens.BlueprintFabricatorScreen;
import dev.amble.ait.client.screens.MonitorScreen;
import dev.amble.ait.client.sonic.SonicModelLoader;
import dev.amble.ait.client.sounds.flight.ExteriorFlightSound;
import dev.amble.ait.client.tardis.ClientTardis;
import dev.amble.ait.client.tardis.manager.ClientTardisManager;
import dev.amble.ait.client.util.ClientTardisUtil;
Expand Down Expand Up @@ -245,6 +249,38 @@ public void onInitializeClient() {
console.setVariant(id);
});

ClientPlayNetworking.registerGlobalReceiver(PLAY_FLIGHT_SOUND, (client, handler, buf, responseSender) -> {
UUID id = buf.readUuid();
UUID tardisID = buf.readUuid();

ClientTardisManager.getInstance().getTardis(tardisID, tardis -> {
ExteriorFlightSound sound = ExteriorFlightSound.INSTANCES.get(client.world.getPlayerByUuid(id)) == null ?
new ExteriorFlightSound(tardis.stats().getFlightEffects(), SoundCategory.PLAYERS, client.world.getPlayerByUuid(id)) :
ExteriorFlightSound.INSTANCES.get(client.world.getPlayerByUuid(id));

client.execute(() -> {
if (client.getSoundManager().isPlaying(sound)) return;
client.getSoundManager().play(sound);
}
);
});
});

ClientPlayNetworking.registerGlobalReceiver(STOP_FLIGHT_SOUND, (client, handler, buf, responseSender) -> {
UUID id = buf.readUuid();
UUID tardisID = buf.readUuid();

ExteriorFlightSound sound = ExteriorFlightSound.INSTANCES.get(client.world.getPlayerByUuid(id));

ClientTardisManager.getInstance().getTardis(tardisID, tardis -> {
client.execute(() -> {
if (!client.getSoundManager().isPlaying(sound)) return;
client.getSoundManager().stop(sound);
}
);
});
});

WorldRenderEvents.END.register((context) -> SonicRendering.getInstance().renderWorld(context));
HudRenderCallback.EVENT.register((context, delta) -> SonicRendering.getInstance().renderGui(context, delta));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.amble.ait.client.config;

import dev.amble.ait.AITMod;
import dev.isxander.yacl3.api.NameableEnum;
import dev.isxander.yacl3.config.v2.api.ConfigClassHandler;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
Expand All @@ -9,8 +8,11 @@
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import dev.isxander.yacl3.gui.ValueFormatters;
import dev.isxander.yacl3.platform.YACLPlatform;

import net.minecraft.text.Text;

import dev.amble.ait.AITMod;

public class AITClientConfig {

public static final String CATEGORY = "client";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;

Expand All @@ -36,7 +37,7 @@ public FlightTardisRenderer(EntityRendererFactory.Context context) {

@Override
public void render(FlightTardisEntity entity, float yaw, float tickDelta, MatrixStack matrices,
VertexConsumerProvider vertexConsumers, int light) {
VertexConsumerProvider vertexConsumers, int light) {
if (!entity.isLinked())
return;

Expand All @@ -52,14 +53,19 @@ public void render(FlightTardisEntity entity, float yaw, float tickDelta, Matrix
if (player.getVehicle() == null || player.getVehicle() != entity) return;

Vec3d vec3d = entity.getRotationVec(tickDelta);
Vec3d vec3d2 = entity.lerpVelocity(tickDelta);
Vec3d vec3d2 = entity.lastVelocity.lerp(entity.lerpVelocity, tickDelta);

if (vec3d2.y < 0.0) {
vec3d2 = vec3d2.normalize();
}

double d = vec3d2.horizontalLengthSquared();
double e = vec3d.horizontalLengthSquared();

matrices.push();
if (tardis.door().isClosed() && !entity.groundCollision)
if (tardis.door().isClosed() && !entity.isOnGround()) {
matrices.translate(0, 0.25f * -vec3d2.getY(), 0);
}

if (tardis.travel().position().getDimension() == AITDimensions.TIME_VORTEX_WORLD) {
VortexRender vortexRender = tardis.stats().getVortexEffects().toRender();
Expand All @@ -78,19 +84,33 @@ public void render(FlightTardisEntity entity, float yaw, float tickDelta, Matrix
}

boolean doorsClosed = tardis.door().isClosed();
float deg = doorsClosed ? (float) (d * 22.5f) : (float) -d * 22.5f;
float rawDeg = doorsClosed ? (float) (d * 22.5f) : (float) (-d * 22.5f);
float maxDoorDeg = 45f;
float deg = MathHelper.clamp(rawDeg, -maxDoorDeg, maxDoorDeg);

if (!entity.verticalCollision && !doorsClosed) {
this.model.getPart().setAngles((float) 0, 0, 0);
if (!entity.isOnGround() && !doorsClosed) {
this.model.getPart().setAngles(0f, 0, 0);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180f));
} else if (!entity.verticalCollision) {
this.model.getPart().setAngles((float) 0, ((entity.getRotation(tickDelta)) * tardis.travel().speed()), 0);
} else if (!entity.isOnGround()) {
this.model.getPart().setAngles(0f, ((entity.getRotation(tickDelta)) * tardis.travel().speed()), 0);
}

/*if (!entity.verticalCollision)
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees((float) (2f * Math.cos(0.2f * (tickDelta + entity.age))) + deg));*/
if (!entity.isOnGround()) {
float xRaw = (float) (2f * Math.cos(0.2f * (tickDelta + entity.age))) + deg;
float maxXTilt = 30f;
float xRot = MathHelper.clamp(xRaw, -maxXTilt, maxXTilt);
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(xRot));
}

matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(entity.verticalCollision ? 180f : (float) (2f * Math.sin(0.2f * (tickDelta + entity.age)) + 180f)));
float zRot;
if (entity.isOnGround()) {
zRot = 180f;
} else {
float zRaw = (float) (2f * Math.sin(0.2f * (tickDelta + entity.age)));
float maxZTilt = 30f;
zRot = MathHelper.clamp(zRaw, -maxZTilt, maxZTilt);
}
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(zRot + (entity.isOnGround() ? 0 : 180)));

this.model.renderEntity(entity, this.model.getPart(), matrices, vertexConsumers.getBuffer(AITRenderLayers.getEntityTranslucentCull(getTexture(entity))), light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);

Expand All @@ -105,8 +125,9 @@ public void render(FlightTardisEntity entity, float yaw, float tickDelta, Matrix
BiomeHandler biome = tardis.handler(TardisComponent.Id.BIOME);
Identifier biomeTexture = biome.getBiomeKey().get(variant.overrides());

if (biomeTexture != null && !this.getTexture(entity).equals(biomeTexture))
if (biomeTexture != null && !this.getTexture(entity).equals(biomeTexture)) {
model.renderEntity(entity, this.model.getPart(), matrices, vertexConsumers.getBuffer(AITRenderLayers.getEntityTranslucentCull(biomeTexture)), light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
}

int maxLight = 0xF000F0;

Expand All @@ -117,6 +138,7 @@ public void render(FlightTardisEntity entity, float yaw, float tickDelta, Matrix
float delta = ((tickDelta + entity.age) * 0.03f);
ShieldsModel shieldsModel = new ShieldsModel(ShieldsModel.getTexturedModelData().createModel());
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEnergySwirl(new Identifier("textures/misc/forcefield.png"), delta % 1.0F, (delta * 0.1F) % 1.0F));
matrices.multiply(RotationAxis.NEGATIVE_Y.rotationDegrees(90 * delta));
shieldsModel.render(matrices, vertexConsumer, maxLight, OverlayTexture.DEFAULT_UV, 0f, 0.25f, 0.5f, 1f);
matrices.pop();
}
Expand Down Expand Up @@ -145,4 +167,4 @@ private void updateModel(Tardis tardis) {
this.model = variant.model();
}
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/dev/amble/ait/client/sounds/LoopingSound.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;

// Referencing how music which loops is done but in our own way
Expand All @@ -32,6 +33,12 @@ public void setPosition(BlockPos pos) {
this.z = pos.getZ();
}

public void setPosition(Vec3d pos) {
this.x = pos.getX();
this.y = pos.getY();
this.z = pos.getZ();
}

public void setPitch(float pitch) {
this.pitch = pitch;
}
Expand All @@ -43,4 +50,8 @@ public void setVolume(float volume) {
public BlockPos getPosition() {
return new BlockPos((int) this.x, (int) this.y, (int) this.z);
}

public Vec3d getPosition(LoopingSound sound) {
return sound.getPosition().toCenterPos();
}
}
Original file line number Diff line number Diff line change
@@ -1,106 +1,54 @@
package dev.amble.ait.client.sounds.flight;

import java.util.HashMap;
import java.util.Map;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.client.sound.WeightedSoundSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

import dev.amble.ait.client.sounds.PositionedLoopingSound;
import dev.amble.ait.client.sounds.LoopingSound;
import dev.amble.ait.client.tardis.ClientTardis;
import dev.amble.ait.client.util.ClientTardisUtil;
import dev.amble.ait.core.entities.FlightTardisEntity;
import dev.amble.ait.core.sounds.flight.FlightSound;

/**
* Not to be confused with {@link dev.amble.ait.core.tardis.animation.v2.TardisAnimation}'s ability of playing mat/demat sounds.
* Yeah.
*/
public class ExteriorFlightSound extends PositionedLoopingSound implements FlightSoundPlayer {
private FlightSound data;
private int ticks = 0;
private boolean dirty = true;

public ExteriorFlightSound(FlightSound data, SoundCategory soundCategory) {
super(data.sound(), soundCategory, new BlockPos(0,0,0));
this.data = data;
}
// Duzo's code kills me internally so I rewrote this. - Loqor
public class ExteriorFlightSound extends LoopingSound {
private final PlayerEntity player;

@Override
public Identifier getId() {
return data.soundId();
}

@Override
public WeightedSoundSet getSoundSet(SoundManager soundManager) {
if (this.getId().equals(SoundManager.INTENTIONALLY_EMPTY_ID)) {
this.sound = SoundManager.INTENTIONALLY_EMPTY_SOUND;
return SoundManager.INTENTIONALLY_EMPTY_SOUND_SET;
} else {
WeightedSoundSet weightedSoundSet = soundManager.get(this.getId());
if (weightedSoundSet == null) {
this.sound = SoundManager.MISSING_SOUND;
} else {
this.sound = weightedSoundSet.getSound(this.random);
}
public static final Map<PlayerEntity, ExteriorFlightSound> INSTANCES = new HashMap<>();

return weightedSoundSet;
}
public ExteriorFlightSound(FlightSound data, SoundCategory soundCategory, PlayerEntity playerEntity) {
super(data.sound(), soundCategory);
this.setPosition(playerEntity.getPos());
this.repeat = true;
this.repeatDelay = 2;
this.attenuationType = AttenuationType.NONE;
this.player = playerEntity;
this.volume = 1.0f;
}

@Override
public ClientTardis tardis() {
return ClientTardisUtil.getNearestTardis(ClientFlightHandler.MAX_DISTANCE).orElse(null);
}

@Override
public void tick() {
super.tick();
this.ticks++;

if (this.ticks >= (this.getData().length() / this.pitch)) {
this.refresh();
if (this.player.getVehicle() instanceof FlightTardisEntity flight) {
return flight.tardis().get().asClient();
}
return null;
}

@Override
public float getProgress() {
if (this.data == null) return 0f;
return (float) this.ticks / (this.data.length() / this.pitch);
}

@Override
public void refresh() {
ClientTardis tardis = tardis();
this.pitch = FlightSoundPlayer.getRandomPitch(tardis);

BlockPos pos = tardis != null && tardis.travel().isLanded() ? tardis.travel().position().getPos() : BlockPos.ORIGIN;

this.setPosition(pos);
this.ticks = 0;
public void tick() {

if (this.dirty || tardis == null) {
if (player.getVehicle() instanceof FlightTardisEntity flight) {
ClientTardis tardis = tardis();
if (tardis == null) {
MinecraftClient.getInstance().getSoundManager().stop(this);
return;
}
this.pitch = FlightSoundPlayer.getRandomPitch(tardis);
} else {
MinecraftClient.getInstance().getSoundManager().stop(this);
return;
}

this.dirty = true;
}

@Override
public FlightSound getData() {
if (this.data == null && tardis() != null)
this.data = tardis().stats().getFlightEffects();

return this.data;
}

@Override
public boolean isDirty() {
return this.dirty;
}

@Override
public void setDirty(boolean dirty) {
this.dirty = dirty;
this.setDone();
}
}
Loading