mirror of
https://github.com/xSquishyLiam/mc-GeyserModelEngine-plugin.git
synced 2025-12-19 14:59:19 +00:00
fix and mount
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -125,7 +125,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
<artifactId>ProtocolLib</artifactId>
|
<artifactId>ProtocolLib</artifactId>
|
||||||
<version>5.1.0</version>
|
<version>5.3.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import re.imc.geysermodelengine.listener.ModelListener;
|
import re.imc.geysermodelengine.listener.ModelListener;
|
||||||
import re.imc.geysermodelengine.listener.MountPacketListener;
|
import re.imc.geysermodelengine.listener.MountPacketListener;
|
||||||
|
import re.imc.geysermodelengine.model.BedrockMountControl;
|
||||||
import re.imc.geysermodelengine.model.ModelEntity;
|
import re.imc.geysermodelengine.model.ModelEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -97,6 +98,7 @@ public final class GeyserModelEngine extends JavaPlugin {
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
}, 100);
|
}, 100);
|
||||||
|
BedrockMountControl.startTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.comphenix.protocol.wrappers.Pair;
|
|||||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||||
import com.ticxo.modelengine.api.model.bone.type.Mount;
|
import com.ticxo.modelengine.api.model.bone.type.Mount;
|
||||||
|
import com.ticxo.modelengine.api.mount.controller.MountController;
|
||||||
import org.geysermc.floodgate.api.FloodgateApi;
|
import org.geysermc.floodgate.api.FloodgateApi;
|
||||||
import re.imc.geysermodelengine.GeyserModelEngine;
|
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class MountPacketListener extends PacketAdapter {
|
public class MountPacketListener extends PacketAdapter {
|
||||||
public MountPacketListener() {
|
public MountPacketListener() {
|
||||||
super(GeyserModelEngine.getInstance(), ListenerPriority.HIGHEST, Set.of(PacketType.Play.Client.STEER_VEHICLE, PacketType.Play.Client.ENTITY_ACTION), ListenerOptions.SYNC);
|
super(GeyserModelEngine.getInstance(), ListenerPriority.HIGHEST, Set.of(PacketType.Play.Client.ENTITY_ACTION), ListenerOptions.ASYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,37 +27,10 @@ public class MountPacketListener extends PacketAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getPacket().getType() == PacketType.Play.Client.STEER_VEHICLE) {
|
Pair<ActiveModel, Mount> seat = GeyserModelEngine.getInstance().getDrivers().get(event.getPlayer());
|
||||||
Pair<ActiveModel, Mount> seat = GeyserModelEngine.getInstance().getDrivers().get(event.getPlayer());
|
if (seat != null) {
|
||||||
if (seat != null) {
|
if (event.getPacket().getPlayerActions().read(0) == EnumWrappers.PlayerAction.START_SNEAKING) {
|
||||||
float pitch = event.getPlayer().getPitch();
|
ModelEngineAPI.getMountPairManager().tryDismount(event.getPlayer());
|
||||||
if (seat.getFirst().getModeledEntity().getBase().isFlying()) {
|
|
||||||
if (pitch < -30) {
|
|
||||||
event.getPacket().getBooleans().writeSafely(0, true);
|
|
||||||
}
|
|
||||||
if (pitch > 45) {
|
|
||||||
event.getPacket().getBooleans().writeSafely(1, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (event.getPlayer().getInventory().getHeldItemSlot() == 0) {
|
|
||||||
event.getPacket().getBooleans().writeSafely(0, true);
|
|
||||||
event.getPlayer().getInventory().setHeldItemSlot(3);
|
|
||||||
}
|
|
||||||
if (pitch > 89 || event.getPlayer().getInventory().getHeldItemSlot() == 1) {
|
|
||||||
event.getPacket().getBooleans().writeSafely(1, true);
|
|
||||||
}
|
|
||||||
if (event.getPlayer().getInventory().getHeldItemSlot() == 8) {
|
|
||||||
event.getPacket().getBooleans().writeSafely(0, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Pair<ActiveModel, Mount> seat = GeyserModelEngine.getInstance().getDrivers().get(event.getPlayer());
|
|
||||||
if (seat != null) {
|
|
||||||
if (event.getPacket().getPlayerActions().read(0) == EnumWrappers.PlayerAction.START_SNEAKING) {
|
|
||||||
event.getPlayer().sendActionBar("leave");
|
|
||||||
ModelEngineAPI.getMountPairManager().tryDismount(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package re.imc.geysermodelengine.model;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.wrappers.Pair;
|
||||||
|
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||||
|
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||||
|
import com.ticxo.modelengine.api.model.bone.type.Mount;
|
||||||
|
import com.ticxo.modelengine.api.mount.controller.MountController;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||||
|
|
||||||
|
public class BedrockMountControl {
|
||||||
|
|
||||||
|
public static void startTask() {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
float pitch = player.getPitch();
|
||||||
|
Pair<ActiveModel, Mount> seat = GeyserModelEngine.getInstance().getDrivers().get(player);
|
||||||
|
if (seat != null) {
|
||||||
|
if (pitch < -30) {
|
||||||
|
MountController controller = ModelEngineAPI.getMountPairManager()
|
||||||
|
.getController(player.getUniqueId());
|
||||||
|
if (controller != null) {
|
||||||
|
MountController.MountInput input = controller.getInput();
|
||||||
|
if (input != null) {
|
||||||
|
input.setJump(true);
|
||||||
|
controller.setInput(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pitch > 50) {
|
||||||
|
MountController controller = ModelEngineAPI.getMountPairManager()
|
||||||
|
.getController(player.getUniqueId());
|
||||||
|
if (controller != null) {
|
||||||
|
MountController.MountInput input = controller.getInput();
|
||||||
|
if (input != null) {
|
||||||
|
input.setSneak(true);
|
||||||
|
controller.setInput(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}.runTaskTimerAsynchronously(GeyserModelEngine.getInstance(), 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package re.imc.geysermodelengine.model;
|
package re.imc.geysermodelengine.model;
|
||||||
|
|
||||||
import com.ticxo.modelengine.api.animation.BlueprintAnimation;
|
import com.ticxo.modelengine.api.animation.BlueprintAnimation;
|
||||||
|
import com.ticxo.modelengine.api.animation.ModelState;
|
||||||
|
import com.ticxo.modelengine.api.animation.handler.AnimationHandler;
|
||||||
|
import com.ticxo.modelengine.api.animation.handler.IStateMachineHandler;
|
||||||
import com.ticxo.modelengine.api.entity.BaseEntity;
|
import com.ticxo.modelengine.api.entity.BaseEntity;
|
||||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||||
@@ -58,6 +61,7 @@ public class EntityTask {
|
|||||||
private BukkitRunnable asyncTask;
|
private BukkitRunnable asyncTask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public EntityTask(ModelEntity model) {
|
public EntityTask(ModelEntity model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
@@ -139,18 +143,22 @@ public class EntityTask {
|
|||||||
|
|
||||||
BaseEntity<?> base = modeledEntity.getBase();
|
BaseEntity<?> base = modeledEntity.getBase();
|
||||||
|
|
||||||
if (base.isStrafing() && hasAnimation("strafe")) {
|
AnimationHandler handler = activeModel.getAnimationHandler();
|
||||||
playAnimation("strafe", 50);
|
if (base.isStrafing()) {
|
||||||
} else if (base.isFlying() && hasAnimation("fly")) {
|
playAnimation(handler.getDefaultProperty(ModelState.STRAFE).getAnimation(), 50);
|
||||||
playAnimation("fly", 40);
|
} else if (base.isFlying()) {
|
||||||
} else if (base.isJumping() && hasAnimation("jump")) {
|
if (base.isWalking()) {
|
||||||
playAnimation("jump", 30);
|
playAnimation(handler.getDefaultProperty(ModelState.FLY).getAnimation(), 40);
|
||||||
} else if (base.isWalking() && hasAnimation("walk")) {
|
} else {
|
||||||
playAnimation("walk", 20);
|
playAnimation(handler.getDefaultProperty(ModelState.HOVER).getAnimation(), 40);
|
||||||
} else if (hasAnimation("idle")) {
|
}
|
||||||
playAnimation("idle", 0);
|
} else if (base.isJumping()) {
|
||||||
|
playAnimation(handler.getDefaultProperty(ModelState.JUMP).getAnimation(), 30);
|
||||||
|
} else if (base.isWalking()) {
|
||||||
|
playAnimation(handler.getDefaultProperty(ModelState.WALK).getAnimation(), 20);
|
||||||
|
} else if (hasAnimation(handler.getDefaultProperty(ModelState.IDLE).getAnimation())) {
|
||||||
|
playAnimation(handler.getDefaultProperty(ModelState.IDLE).getAnimation(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (animationCooldown.get() > 0) {
|
if (animationCooldown.get() > 0) {
|
||||||
animationCooldown.decrementAndGet();
|
animationCooldown.decrementAndGet();
|
||||||
}
|
}
|
||||||
@@ -160,8 +168,8 @@ public class EntityTask {
|
|||||||
updateEntityProperties(player.get(), false);
|
updateEntityProperties(player.get(), false);
|
||||||
|
|
||||||
// do not actually use this, atleast bundle these up ;(
|
// do not actually use this, atleast bundle these up ;(
|
||||||
sendScale(player.get(), true);
|
sendScale(player.get(), false);
|
||||||
sendColor(player.get(), true);
|
sendColor(player.get(), false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,29 +199,33 @@ public class EntityTask {
|
|||||||
}
|
}
|
||||||
sendHitBox(player);
|
sendHitBox(player);
|
||||||
sendScale(player, true);
|
sendScale(player, true);
|
||||||
|
sendColor(player, true);
|
||||||
updateEntityProperties(player, true);
|
updateEntityProperties(player, true);
|
||||||
}, 8);
|
}, 8);
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendScale(Player player, boolean ignore) {
|
public void sendScale(Player player, boolean firstSend) {
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
Vector3f scale = model.getActiveModel().getScale();
|
Vector3f scale = model.getActiveModel().getScale();
|
||||||
float average = (scale.x + scale.y + scale.z) / 3;
|
float average = (scale.x + scale.y + scale.z) / 3;
|
||||||
if (average == lastScale) return;
|
|
||||||
|
|
||||||
|
if (!firstSend) {
|
||||||
|
if (average == lastScale) return;
|
||||||
|
}
|
||||||
EntityUtils.sendCustomScale(player, model.getEntity().getEntityId(), average);
|
EntityUtils.sendCustomScale(player, model.getEntity().getEntityId(), average);
|
||||||
|
|
||||||
lastScale = average;
|
lastScale = average;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendColor(Player player, boolean ignore) {
|
public void sendColor(Player player, boolean firstSend) {
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
Color color = new Color(model.getActiveModel().getDefaultTint().asARGB());
|
Color color = new Color(model.getActiveModel().getDefaultTint().asARGB());
|
||||||
if (color.equals(lastColor)) return;
|
if (firstSend) {
|
||||||
|
if (color.equals(lastColor)) return;
|
||||||
|
}
|
||||||
EntityUtils.sendCustomColor(player, model.getEntity().getEntityId(), color);
|
EntityUtils.sendCustomColor(player, model.getEntity().getEntityId(), color);
|
||||||
|
|
||||||
lastColor = color;
|
lastColor = color;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package re.imc.geysermodelengine.packet.entity;
|
package re.imc.geysermodelengine.packet.entity;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -20,6 +21,8 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class PacketEntity {
|
public class PacketEntity {
|
||||||
|
|
||||||
|
public static final MinecraftVersion V1_20_5 = new MinecraftVersion("1.20.5");
|
||||||
public PacketEntity(EntityType type, Set<Player> viewers, Location location) {
|
public PacketEntity(EntityType type, Set<Player> viewers, Location location) {
|
||||||
this.id = ThreadLocalRandom.current().nextInt(300000000, 400000000);
|
this.id = ThreadLocalRandom.current().nextInt(300000000, 400000000);
|
||||||
this.uuid = UUID.randomUUID();
|
this.uuid = UUID.randomUUID();
|
||||||
@@ -89,8 +92,11 @@ public class PacketEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendHurtPacket(Collection<Player> players) {
|
public void sendHurtPacket(Collection<Player> players) {
|
||||||
EntityHurtPacket packet = new EntityHurtPacket(id);
|
// 1.21 error
|
||||||
players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode()));
|
if (MinecraftVersion.getCurrentVersion().compareTo(V1_20_5) < 0) {
|
||||||
|
EntityHurtPacket packet = new EntityHurtPacket(id);
|
||||||
|
players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendEntityDestroyPacket(Collection<Player> players) {
|
public void sendEntityDestroyPacket(Collection<Player> players) {
|
||||||
|
|||||||
Reference in New Issue
Block a user