fix: correct display pos/rot interpolation metadata index, minor cleanup

This commit is contained in:
mworzala 2023-11-30 10:31:10 +02:00 committed by Matt Worzala
parent 0665f17c33
commit ccdc5535e3
4 changed files with 19 additions and 34 deletions

View File

@ -6,6 +6,7 @@ import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Command; import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext; import net.minestom.server.command.builder.CommandContext;
import net.minestom.server.command.builder.arguments.ArgumentType; import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.entity.Entity; import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType; import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
@ -41,6 +42,7 @@ public class DisplayCommand extends Command {
var entity = new Entity(EntityType.ITEM_DISPLAY); var entity = new Entity(EntityType.ITEM_DISPLAY);
var meta = (ItemDisplayMeta) entity.getEntityMeta(); var meta = (ItemDisplayMeta) entity.getEntityMeta();
meta.setTransformationInterpolationDuration(20);
meta.setItemStack(ItemStack.of(Material.STICK)); meta.setItemStack(ItemStack.of(Material.STICK));
entity.setInstance(player.getInstance(), player.getPosition()); entity.setInstance(player.getInstance(), player.getPosition());
@ -55,8 +57,9 @@ public class DisplayCommand extends Command {
var entity = new Entity(EntityType.BLOCK_DISPLAY); var entity = new Entity(EntityType.BLOCK_DISPLAY);
var meta = (BlockDisplayMeta) entity.getEntityMeta(); var meta = (BlockDisplayMeta) entity.getEntityMeta();
meta.setBlockState(Block.STONE_STAIRS.stateId()); meta.setTransformationInterpolationDuration(20);
entity.setInstance(player.getInstance(), player.getPosition()); meta.setBlockState(Block.ORANGE_CANDLE_CAKE.stateId());
entity.setInstance(player.getInstance(), player.getPosition()).join();
if (context.has("follow")) { if (context.has("follow")) {
startSmoothFollow(entity, player); startSmoothFollow(entity, player);
@ -69,6 +72,7 @@ public class DisplayCommand extends Command {
var entity = new Entity(EntityType.TEXT_DISPLAY); var entity = new Entity(EntityType.TEXT_DISPLAY);
var meta = (TextDisplayMeta) entity.getEntityMeta(); var meta = (TextDisplayMeta) entity.getEntityMeta();
meta.setTransformationInterpolationDuration(20);
meta.setBillboardRenderConstraints(AbstractDisplayMeta.BillboardConstraints.CENTER); meta.setBillboardRenderConstraints(AbstractDisplayMeta.BillboardConstraints.CENTER);
meta.setText(Component.text("Hello, world!")); meta.setText(Component.text("Hello, world!"));
entity.setInstance(player.getInstance(), player.getPosition()); entity.setInstance(player.getInstance(), player.getPosition());
@ -79,11 +83,16 @@ public class DisplayCommand extends Command {
} }
private void startSmoothFollow(@NotNull Entity entity, @NotNull Player player) { private void startSmoothFollow(@NotNull Entity entity, @NotNull Player player) {
// entity.setCustomName(Component.text("MY CUSTOM NAME"));
// entity.setCustomNameVisible(true);
MinecraftServer.getSchedulerManager().buildTask(() -> { MinecraftServer.getSchedulerManager().buildTask(() -> {
var meta = (AbstractDisplayMeta) entity.getEntityMeta(); var meta = (AbstractDisplayMeta) entity.getEntityMeta();
meta.setNotifyAboutChanges(false); meta.setNotifyAboutChanges(false);
meta.setInterpolationStartDelta(1); meta.setTransformationInterpolationStartDelta(1);
meta.setInterpolationDuration(20); meta.setTransformationInterpolationDuration(20);
// meta.setPosRotInterpolationDuration(20);
// entity.teleport(player.getPosition());
// meta.setScale(new Vec(5, 5, 5));
meta.setTranslation(player.getPosition().sub(entity.getPosition())); meta.setTranslation(player.getPosition().sub(entity.getPosition()));
meta.setNotifyAboutChanges(true); meta.setNotifyAboutChanges(true);
}).delay(20, TimeUnit.SERVER_TICK).repeat(20, TimeUnit.SERVER_TICK).schedule(); }).delay(20, TimeUnit.SERVER_TICK).repeat(20, TimeUnit.SERVER_TICK).schedule();

View File

@ -16,27 +16,27 @@ public class AbstractDisplayMeta extends EntityMeta {
super(entity, metadata); super(entity, metadata);
} }
public long getPosRotInterpolationDuration() { public long getTransformationInterpolationStartDelta() {
return super.metadata.getIndex(OFFSET, 0); return super.metadata.getIndex(OFFSET, 0);
} }
public void setPosRotInterpolationDuration(int value) { public void setTransformationInterpolationStartDelta(int value) {
super.metadata.setIndex(OFFSET, Metadata.VarInt(value)); super.metadata.setIndex(OFFSET, Metadata.VarInt(value));
} }
public long getTransformationInterpolationStartDelta() { public int getTransformationInterpolationDuration() {
return super.metadata.getIndex(OFFSET + 1, 0); return super.metadata.getIndex(OFFSET + 1, 0);
} }
public void setTransformationInterpolationStartDelta(int value) { public void setTransformationInterpolationDuration(int value) {
super.metadata.setIndex(OFFSET + 1, Metadata.VarInt(value)); super.metadata.setIndex(OFFSET + 1, Metadata.VarInt(value));
} }
public int getTransformationInterpolationDuration() { public long getPosRotInterpolationDuration() {
return super.metadata.getIndex(OFFSET + 2, 0); return super.metadata.getIndex(OFFSET + 2, 0);
} }
public void setTransformationInterpolationDuration(int value) { public void setPosRotInterpolationDuration(int value) {
super.metadata.setIndex(OFFSET + 2, Metadata.VarInt(value)); super.metadata.setIndex(OFFSET + 2, Metadata.VarInt(value));
} }

View File

@ -8,14 +8,12 @@ import net.minestom.server.listener.common.KeepAliveListener;
import net.minestom.server.listener.common.PluginMessageListener; import net.minestom.server.listener.common.PluginMessageListener;
import net.minestom.server.listener.common.ResourcePackListener; import net.minestom.server.listener.common.ResourcePackListener;
import net.minestom.server.listener.common.SettingsListener; import net.minestom.server.listener.common.SettingsListener;
import net.minestom.server.listener.preplay.ConfigurationListener;
import net.minestom.server.listener.preplay.HandshakeListener; import net.minestom.server.listener.preplay.HandshakeListener;
import net.minestom.server.listener.preplay.LoginListener; import net.minestom.server.listener.preplay.LoginListener;
import net.minestom.server.listener.preplay.StatusListener; import net.minestom.server.listener.preplay.StatusListener;
import net.minestom.server.network.ConnectionState; import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.packet.client.ClientPacket; import net.minestom.server.network.packet.client.ClientPacket;
import net.minestom.server.network.packet.client.common.*; import net.minestom.server.network.packet.client.common.*;
import net.minestom.server.network.packet.client.configuration.ClientFinishConfigurationPacket;
import net.minestom.server.network.packet.client.handshake.ClientHandshakePacket; import net.minestom.server.network.packet.client.handshake.ClientHandshakePacket;
import net.minestom.server.network.packet.client.login.ClientEncryptionResponsePacket; import net.minestom.server.network.packet.client.login.ClientEncryptionResponsePacket;
import net.minestom.server.network.packet.client.login.ClientLoginAcknowledgedPacket; import net.minestom.server.network.packet.client.login.ClientLoginAcknowledgedPacket;
@ -55,7 +53,6 @@ public final class PacketListenerManager {
setConfigurationListener(ClientSettingsPacket.class, SettingsListener::listener); setConfigurationListener(ClientSettingsPacket.class, SettingsListener::listener);
setConfigurationListener(ClientPluginMessagePacket.class, PluginMessageListener::listener); setConfigurationListener(ClientPluginMessagePacket.class, PluginMessageListener::listener);
setConfigurationListener(ClientFinishConfigurationPacket.class, ConfigurationListener::finishListener);
setConfigurationListener(ClientKeepAlivePacket.class, KeepAliveListener::listener); setConfigurationListener(ClientKeepAlivePacket.class, KeepAliveListener::listener);
setConfigurationListener(ClientPongPacket.class, (packet, player) -> {/* empty */}); setConfigurationListener(ClientPongPacket.class, (packet, player) -> {/* empty */});
setConfigurationListener(ClientResourcePackStatusPacket.class, ResourcePackListener::listener); setConfigurationListener(ClientResourcePackStatusPacket.class, ResourcePackListener::listener);

View File

@ -1,21 +0,0 @@
package net.minestom.server.listener.preplay;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import net.minestom.server.network.ConnectionManager;
import net.minestom.server.network.packet.client.configuration.ClientFinishConfigurationPacket;
import org.jetbrains.annotations.NotNull;
public final class ConfigurationListener {
private static final ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager();
public static void finishListener(@NotNull ClientFinishConfigurationPacket packet, @NotNull Player player) {
// player.getPlayerConnection().setClientState(ConnectionState.PLAY);
System.out.println("Finished configuration for " + player.getUsername() );
//todo move to play state
}
}