mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2026-01-03 14:22:14 +00:00
Balloon Now Works!
This commit is contained in:
@@ -27,13 +27,12 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||
|
||||
final Location actual = player.getLocation().clone().add(Settings.getBalloonOffset());
|
||||
final Location previous = user.getBalloonEntity().getLocation();
|
||||
final Vector vector = user.getBalloonEntity().getLocation().toVector();
|
||||
if (vector != null) actual.add(user.getBalloonEntity().getLocation().toVector().multiply(-1));
|
||||
//final Location previous = user.getBalloonEntity().getLocation();
|
||||
//final Vector vector = user.getBalloonEntity().getLocation().toVector();
|
||||
//if (vector != null) actual.add(user.getBalloonEntity().getLocation().toVector().multiply(-1));
|
||||
|
||||
user.getBalloonEntity().setLocation(actual);
|
||||
user.getBalloonEntity().setVelocity(actual.clone().subtract(previous.clone()).toVector());
|
||||
user.getBalloonEntity().updateModel();
|
||||
user.getBalloonEntity().getModelEntity().moveTo(actual.getX(), actual.getY(), actual.getZ());
|
||||
//user.getBalloonEntity().setVelocity(actual.clone().subtract(previous.clone()).toVector());
|
||||
|
||||
PacketManager.sendTeleportPacket(user.getBalloonEntity().getPufferfishBalloonId(), actual, false, PlayerUtils.getNearbyPlayers(player));
|
||||
PacketManager.sendLeashPacket(user.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), PlayerUtils.getNearbyPlayers(player));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.entities;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
@@ -16,26 +17,12 @@ public class BalloonEntity {
|
||||
|
||||
private final int balloonID;
|
||||
private final UUID uniqueID;
|
||||
private final MEGEntity megEntity;
|
||||
private final MEGEntity modelEntity;
|
||||
|
||||
public BalloonEntity(Location location) {
|
||||
this.uniqueID = UUID.randomUUID();
|
||||
this.balloonID = Entity.nextEntityId();
|
||||
this.megEntity = new MEGEntity(UUID.randomUUID(), Entity.nextEntityId(), new Vector(0, 0, 0), location, false);
|
||||
}
|
||||
|
||||
public void updateModel() {
|
||||
this.megEntity.update();
|
||||
/*
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId());
|
||||
|
||||
if (model == null) return;
|
||||
|
||||
if (model.getBase() instanceof final MEGEntity e) {
|
||||
//HMCCosmeticsPlugin.getInstance().getLogger().info("Updated Model");
|
||||
e.update(this);
|
||||
}
|
||||
*/
|
||||
this.modelEntity = new MEGEntity(location.add(Settings.getBalloonOffset()));
|
||||
}
|
||||
|
||||
public void spawnModel(final String id) {
|
||||
@@ -44,14 +31,13 @@ public class BalloonEntity {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().warning("Invalid Model Engine Blueprint " + id);
|
||||
return;
|
||||
}
|
||||
//HMCCosmeticsPlugin.getInstance().getLogger().warning("Possible Blueprints" + ModelEngineAPI.api.getModelRegistry().getAllBlueprintId());
|
||||
ActiveModel model = ModelEngineAPI.api.createActiveModelImpl(ModelEngineAPI.api.getModelRegistry().getBlueprint(id));
|
||||
ModeledEntity modeledEntity = ModelEngineAPI.api.createModeledEntityImpl(megEntity);
|
||||
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity.getBukkitEntity());
|
||||
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
|
||||
modeledEntity.addModel(model, false);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId());
|
||||
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUUID());
|
||||
|
||||
if (entity == null) return;
|
||||
|
||||
@@ -64,32 +50,26 @@ public class BalloonEntity {
|
||||
}
|
||||
|
||||
public void addPlayerToModel(final Player player, final String id) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId());
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUUID());
|
||||
if (model == null) {
|
||||
spawnModel(id);
|
||||
return;
|
||||
}
|
||||
//if (megEntity.getRangeManager().getPlayerInRange().contains(player)) return;
|
||||
if (model.getRangeManager().getPlayerInRange().contains(player)) return;
|
||||
model.showToPlayer(player);
|
||||
}
|
||||
|
||||
public void addPlayerToModel(final Player player) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId());
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
//if (megEntity.getRangeManager().getPlayerInRange().contains(player)) return;
|
||||
model.showToPlayer(player);
|
||||
}
|
||||
|
||||
public void removePlayerFromModel(final Player player) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId());
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUUID());
|
||||
|
||||
if (model == null) return;
|
||||
|
||||
model.hideFromPlayer(player);
|
||||
}
|
||||
|
||||
public MEGEntity getModelEntity() {
|
||||
return this.modelEntity;
|
||||
}
|
||||
|
||||
|
||||
public int getPufferfishBalloonId() {
|
||||
return balloonID;
|
||||
@@ -99,30 +79,27 @@ public class BalloonEntity {
|
||||
}
|
||||
|
||||
public UUID getModelUnqiueId() {
|
||||
return megEntity.getUniqueId();
|
||||
return modelEntity.getUUID();
|
||||
}
|
||||
|
||||
public int getModelId() {
|
||||
return megEntity.getEntityId();
|
||||
return modelEntity.getId();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.megEntity.getLocation();
|
||||
return this.modelEntity.getBukkitEntity().getLocation();
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return this.megEntity.isAlive();
|
||||
return this.modelEntity.isAlive();
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.megEntity.setLocation(location);
|
||||
//this.megEntity.teleportTo(location.getX(), location.getY(), location.getZ());
|
||||
this.modelEntity.getBukkitEntity().teleport(location);
|
||||
}
|
||||
|
||||
public void setVelocity(Vector vector) {
|
||||
this.megEntity.setVelocity(vector);
|
||||
}
|
||||
|
||||
public void setAlive(boolean alive) {
|
||||
this.megEntity.setAlive(alive);
|
||||
this.modelEntity.getBukkitEntity().setVelocity(vector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,246 +1,25 @@
|
||||
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 com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.ambient.Bat;
|
||||
import net.minecraft.world.entity.animal.Chicken;
|
||||
import net.minecraft.world.entity.animal.Pufferfish;
|
||||
import net.minecraft.world.entity.monster.Slime;
|
||||
import net.minecraft.world.entity.projectile.DragonFireball;
|
||||
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 org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
public class MEGEntity extends Chicken {
|
||||
|
||||
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<Entity> passengers;
|
||||
private RangeManager rangeManager;
|
||||
|
||||
public 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<>();
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(uuid);
|
||||
this.rangeManager = new ManualRangeManager(this, model);
|
||||
this.rangeManager.setRenderDistance(32);
|
||||
}
|
||||
|
||||
public MEGEntity(final UUID uuid, final int entityId) {
|
||||
this.uuid = uuid;
|
||||
this.entityId = entityId;
|
||||
this.alive = false;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
for (Player player : rangeManager.getPlayerInRange()) {
|
||||
rangeManager.updatePlayer(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<Entity> getPassengers() {
|
||||
return this.passengers;
|
||||
}
|
||||
|
||||
public Vector getVelocity() {
|
||||
return velocity;
|
||||
public MEGEntity(Location loc) {
|
||||
super(EntityType.CHICKEN, ((CraftWorld) loc.getWorld()).getHandle());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Spawned MEGEntity at " + loc);
|
||||
getBukkitLivingEntity().setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setNoAi(true);
|
||||
setNoGravity(true);
|
||||
persist = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,11 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
|
||||
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 com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -169,9 +172,10 @@ public class CosmeticUser {
|
||||
if (this.balloonEntity != null) return;
|
||||
BalloonEntity balloonEntity1 = new BalloonEntity(player.getLocation());
|
||||
|
||||
((CraftWorld) player.getWorld()).getHandle().addFreshEntity(balloonEntity1.getModelEntity(), CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
balloonEntity1.spawnModel(cosmeticBalloonType.getModelName());
|
||||
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName());
|
||||
balloonEntity1.updateModel();
|
||||
|
||||
PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo);
|
||||
PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo);
|
||||
@@ -182,6 +186,9 @@ public class CosmeticUser {
|
||||
|
||||
public void despawnBalloon() {
|
||||
if (this.balloonEntity == null) return;
|
||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(getPlayer().getLocation());
|
||||
|
||||
PacketManager.sendEntityDestroyPacket(balloonEntity.getPufferfishBalloonId(), sentTo);
|
||||
|
||||
this.balloonEntity.remove();
|
||||
this.balloonEntity = null;
|
||||
|
||||
Reference in New Issue
Block a user