From b7d77d9695cb06ba845ace3eb74e029fc8ab8761 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 15 Nov 2022 19:14:39 -0600 Subject: [PATCH] =?UTF-8?q?Balloons=20work=20=F0=9F=8E=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 1 + .../cosmetic/types/CosmeticBackpackType.java | 2 +- .../cosmetic/types/CosmeticBalloonType.java | 25 ++ .../hmccosmetics/entities/MEGEntity.java | 293 ++++++++++++++++++ .../hmccosmetics/user/CosmeticUser.java | 5 + 5 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hibiscusmc/hmccosmetics/entities/MEGEntity.java diff --git a/build.gradle.kts b/build.gradle.kts index 6a025389..0752c9e7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,6 +17,7 @@ bukkit { apiVersion = "1.19" authors = listOf("LoJoSho") depend = listOf("ProtocolLib") + softDepend = listOf("ModelEngine") version = "${project.version}" commands { diff --git a/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBackpackType.java b/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBackpackType.java index c0cd0e3a..64f19ff0 100644 --- a/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBackpackType.java +++ b/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBackpackType.java @@ -30,7 +30,7 @@ public class CosmeticBackpackType extends Cosmetic { public void update(CosmeticUser user) { Player player = Bukkit.getPlayer(user.getUniqueId()); List sendTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - Location loc = player.getLocation(); + Location loc = player.getLocation().clone(); user.getBackpackEntity().getBukkitLivingEntity().setRotation(loc.getYaw(), loc.getPitch()); diff --git a/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java b/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java index 1134bc49..f37d2acd 100644 --- a/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java +++ b/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java @@ -1,10 +1,35 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types; +import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; +import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import com.hibiscusmc.hmccosmetics.util.PlayerUtils; +import com.ticxo.modelengine.api.generator.model.ModelBlueprint; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; import org.spongepowered.configurate.ConfigurationNode; +import java.util.List; + public class CosmeticBalloonType extends Cosmetic { + + private ModelBlueprint model; public CosmeticBalloonType(String id, ConfigurationNode config) { super(id, config); } + + @Override + public void update(CosmeticUser user) { + Player player = Bukkit.getPlayer(user.getUniqueId()); + List sendTo = PlayerUtils.getNearbyPlayers(player.getLocation()); + Location loc = player.getLocation().clone(); + + // TODO: Offsets + loc.add(Settings.getBalloonOffset()); + user.getBalloonEntity().setLocation(loc); + + //user.getBackpackEntity().getBukkitLivingEntity().setRotation(loc.getYaw(), loc.getPitch()); + + } } diff --git a/src/main/java/com/hibiscusmc/hmccosmetics/entities/MEGEntity.java b/src/main/java/com/hibiscusmc/hmccosmetics/entities/MEGEntity.java new file mode 100644 index 00000000..6938393d --- /dev/null +++ b/src/main/java/com/hibiscusmc/hmccosmetics/entities/MEGEntity.java @@ -0,0 +1,293 @@ +package com.hibiscusmc.hmccosmetics.entities; + +import com.ticxo.modelengine.api.ModelEngineAPI; +import com.ticxo.modelengine.api.entity.BaseEntity; +import com.ticxo.modelengine.api.generator.Hitbox; +import com.ticxo.modelengine.api.model.ActiveModel; +import com.ticxo.modelengine.api.model.IModel; +import com.ticxo.modelengine.api.model.ModeledEntity; +import com.ticxo.modelengine.api.nms.entity.impl.DefaultBodyRotationController; +import com.ticxo.modelengine.api.nms.entity.impl.EmptyRangeManager; +import com.ticxo.modelengine.api.nms.entity.impl.ManualRangeManager; +import com.ticxo.modelengine.api.nms.entity.wrapper.BodyRotationController; +import com.ticxo.modelengine.api.nms.entity.wrapper.LookController; +import com.ticxo.modelengine.api.nms.entity.wrapper.MoveController; +import com.ticxo.modelengine.api.nms.entity.wrapper.RangeManager; +import com.ticxo.modelengine.api.nms.world.IDamageSource; +import com.ticxo.modelengine.api.utils.data.EntityData; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class MEGEntity implements BaseEntity { + private final UUID uuid; + private final int entityId; + private Vector velocity = new Vector(0, 0, 0); + private Location location; + private boolean alive; + private BodyRotationController rotationController; + private List passengers; + private RangeManager rangeManager; + + protected MEGEntity(final UUID uuid, final int entityId, final Vector velocity, final Location location, final boolean alive) { + this.uuid = uuid; + this.entityId = entityId; + this.velocity = velocity; + this.location = location; + this.alive = alive; + this.rotationController = new DefaultBodyRotationController(this); + this.passengers = new ArrayList<>(); + this.rangeManager = new EmptyRangeManager(); + this.rangeManager.setRenderDistance(16); + } + + protected MEGEntity(final UUID uuid, final int entityId) { + this.uuid = uuid; + this.entityId = entityId; + this.alive = false; + } + + public void update() { + this.velocity = getLocation().toVector(); + this.location = getLocation(); + this.alive = isAlive(); + } + + + public void updateModel() { + final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(getUniqueId()); + + if (model == null) return; + + if (model.getBase() instanceof final MEGEntity e) e.update(); + } + + public void spawnModel(final String id) { + if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) { + return; + } + final ActiveModel model = ModelEngineAPI.api.createActiveModelImpl(ModelEngineAPI.getBlueprint(id)); + ModeledEntity modeledEntity = ModelEngineAPI.api.createModeledEntityImpl(this); + modeledEntity.addModel(model, false); + } + + public void remove() { + final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(getUniqueId()); + + if (entity == null) return; + + for (final Player player : entity.getRangeManager().getPlayerInRange()) { + entity.hideFromPlayer(player); + } + + //ModelEngineAPI.removeModeledEntity(megEntity.getUniqueId()); + entity.destroy(); + } + + public void addPlayerToModel(final Player player, final String id) { + final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(getUniqueId()); + if (model == null) { + this.spawnModel(id); + return; + } + if (getRangeManager().getPlayerInRange().contains(player)) return; + model.showToPlayer(player); + } + + public void removePlayerFromModel(final Player player) { + final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(getUniqueId()); + + if (model == null) return; + + model.hideFromPlayer(player); + } + + public void setVelocity(final Vector velocity) { + this.velocity = velocity; + } + + public void setLocation(final Location location) { + this.location = location; + } + + public void setAlive(final boolean alive) { + this.alive = alive; + } + + public boolean isAlive() { + return alive; + } + + public EntityData getEntityData() { + return entityData; + } + + final EntityData entityData = new EntityData(); + + @Override + public Object getOriginal() { + return null; + } + + @Override + public MoveController wrapMoveControl() { + return null; + } + + @Override + public LookController wrapLookControl() { + return null; + } + + @Override + public BodyRotationController wrapBodyRotationControl() { + return this.rotationController; + } + + @Override + public void wrapNavigation() { + + } + + @Override + public RangeManager wrapRangeManager(IModel model) { + return new ManualRangeManager(this, model); + } + + @Override + public RangeManager getRangeManager() { + if (this.rangeManager == null) { + RangeManager rangeMan = new EmptyRangeManager(); + rangeMan.setRenderDistance(16); + return rangeMan; + } + return this.rangeManager; + } + + @Override + public boolean onHurt(IDamageSource damageSource, float damage) { + return false; + } + + @Override + public void onInteract(Player player, EquipmentSlot hand) { + + } + + @Override + public void setHitbox(Hitbox hitbox) { + + } + + @Override + public Hitbox getHitbox() { + return null; + } + + @Override + public void setStepHeight(double height) { + + } + + @Override + public Double getStepHeight() { + return null; + } + + @Override + public void setCollidableToLiving(LivingEntity living, boolean isRemove) { + + } + + @Override + public void broadcastSpawnPacket() { + + } + + @Override + public void broadcastDespawnPacket() { + + } + + @Override + public int getEntityId() { + return this.entityId; + } + + @Override + public UUID getUniqueId() { + return this.uuid; + } + + @Override + public Location getLocation() { + return location; + } + + @Override + public World getWorld() { + return this.getWorld(); + } + + @Override + public boolean isDead() { + return alive; + } + + @Override + public boolean isGlowing() { + return false; + } + + @Override + public boolean isOnGround() { + return false; + } + + @Override + public boolean isMoving() { + return false; + } + + @Override + public void setYHeadRot(float rot) { + + } + + @Override + public float getYHeadRot() { + return 0; + } + + @Override + public float getXHeadRot() { + return 0; + } + + @Override + public void setYBodyRot(float rot) { + location.setYaw(rot); + } + + @Override + public float getYBodyRot() { + return location.getYaw(); + } + + @Override + public List getPassengers() { + return this.passengers; + } + + public Vector getVelocity() { + return velocity; + } +} diff --git a/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java b/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java index fa0e0c70..0455cb08 100644 --- a/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -6,6 +6,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.entities.InvisibleArmorstand; +import com.hibiscusmc.hmccosmetics.entities.MEGEntity; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import net.minecraft.world.entity.EquipmentSlot; @@ -26,6 +27,7 @@ public class CosmeticUser { private HashMap playerCosmetics = new HashMap<>(); private Wardrobe wardrobe; private InvisibleArmorstand invisibleArmorstand; + private MEGEntity balloonEntity; public CosmeticUser(UUID uuid) { @@ -51,6 +53,9 @@ public class CosmeticUser { public InvisibleArmorstand getBackpackEntity() { return this.invisibleArmorstand; } + public MEGEntity getBalloonEntity() { + return this.balloonEntity; + } public void addPlayerCosmetic(Cosmetic cosmetic) { playerCosmetics.put(cosmetic.getSlot(), cosmetic);