mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
fix: correct display pos/rot interpolation metadata index, minor cleanup
This commit is contained in:
parent
0665f17c33
commit
ccdc5535e3
@ -6,6 +6,7 @@ import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.CommandContext;
|
||||
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.EntityType;
|
||||
import net.minestom.server.entity.Player;
|
||||
@ -41,6 +42,7 @@ public class DisplayCommand extends Command {
|
||||
|
||||
var entity = new Entity(EntityType.ITEM_DISPLAY);
|
||||
var meta = (ItemDisplayMeta) entity.getEntityMeta();
|
||||
meta.setTransformationInterpolationDuration(20);
|
||||
meta.setItemStack(ItemStack.of(Material.STICK));
|
||||
entity.setInstance(player.getInstance(), player.getPosition());
|
||||
|
||||
@ -55,8 +57,9 @@ public class DisplayCommand extends Command {
|
||||
|
||||
var entity = new Entity(EntityType.BLOCK_DISPLAY);
|
||||
var meta = (BlockDisplayMeta) entity.getEntityMeta();
|
||||
meta.setBlockState(Block.STONE_STAIRS.stateId());
|
||||
entity.setInstance(player.getInstance(), player.getPosition());
|
||||
meta.setTransformationInterpolationDuration(20);
|
||||
meta.setBlockState(Block.ORANGE_CANDLE_CAKE.stateId());
|
||||
entity.setInstance(player.getInstance(), player.getPosition()).join();
|
||||
|
||||
if (context.has("follow")) {
|
||||
startSmoothFollow(entity, player);
|
||||
@ -69,6 +72,7 @@ public class DisplayCommand extends Command {
|
||||
|
||||
var entity = new Entity(EntityType.TEXT_DISPLAY);
|
||||
var meta = (TextDisplayMeta) entity.getEntityMeta();
|
||||
meta.setTransformationInterpolationDuration(20);
|
||||
meta.setBillboardRenderConstraints(AbstractDisplayMeta.BillboardConstraints.CENTER);
|
||||
meta.setText(Component.text("Hello, world!"));
|
||||
entity.setInstance(player.getInstance(), player.getPosition());
|
||||
@ -79,11 +83,16 @@ public class DisplayCommand extends Command {
|
||||
}
|
||||
|
||||
private void startSmoothFollow(@NotNull Entity entity, @NotNull Player player) {
|
||||
// entity.setCustomName(Component.text("MY CUSTOM NAME"));
|
||||
// entity.setCustomNameVisible(true);
|
||||
MinecraftServer.getSchedulerManager().buildTask(() -> {
|
||||
var meta = (AbstractDisplayMeta) entity.getEntityMeta();
|
||||
meta.setNotifyAboutChanges(false);
|
||||
meta.setInterpolationStartDelta(1);
|
||||
meta.setInterpolationDuration(20);
|
||||
meta.setTransformationInterpolationStartDelta(1);
|
||||
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.setNotifyAboutChanges(true);
|
||||
}).delay(20, TimeUnit.SERVER_TICK).repeat(20, TimeUnit.SERVER_TICK).schedule();
|
||||
|
@ -16,27 +16,27 @@ public class AbstractDisplayMeta extends EntityMeta {
|
||||
super(entity, metadata);
|
||||
}
|
||||
|
||||
public long getPosRotInterpolationDuration() {
|
||||
public long getTransformationInterpolationStartDelta() {
|
||||
return super.metadata.getIndex(OFFSET, 0);
|
||||
}
|
||||
|
||||
public void setPosRotInterpolationDuration(int value) {
|
||||
public void setTransformationInterpolationStartDelta(int value) {
|
||||
super.metadata.setIndex(OFFSET, Metadata.VarInt(value));
|
||||
}
|
||||
|
||||
public long getTransformationInterpolationStartDelta() {
|
||||
public int getTransformationInterpolationDuration() {
|
||||
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));
|
||||
}
|
||||
|
||||
public int getTransformationInterpolationDuration() {
|
||||
public long getPosRotInterpolationDuration() {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,12 @@ import net.minestom.server.listener.common.KeepAliveListener;
|
||||
import net.minestom.server.listener.common.PluginMessageListener;
|
||||
import net.minestom.server.listener.common.ResourcePackListener;
|
||||
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.LoginListener;
|
||||
import net.minestom.server.listener.preplay.StatusListener;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
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.login.ClientEncryptionResponsePacket;
|
||||
import net.minestom.server.network.packet.client.login.ClientLoginAcknowledgedPacket;
|
||||
@ -55,7 +53,6 @@ public final class PacketListenerManager {
|
||||
|
||||
setConfigurationListener(ClientSettingsPacket.class, SettingsListener::listener);
|
||||
setConfigurationListener(ClientPluginMessagePacket.class, PluginMessageListener::listener);
|
||||
setConfigurationListener(ClientFinishConfigurationPacket.class, ConfigurationListener::finishListener);
|
||||
setConfigurationListener(ClientKeepAlivePacket.class, KeepAliveListener::listener);
|
||||
setConfigurationListener(ClientPongPacket.class, (packet, player) -> {/* empty */});
|
||||
setConfigurationListener(ClientResourcePackStatusPacket.class, ResourcePackListener::listener);
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user