9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2026-01-04 15:41:45 +00:00

Latest Balloon work

This commit is contained in:
LoJoSho
2022-11-19 13:18:32 -06:00
parent 0959acde35
commit eb0b9ae739
6 changed files with 39 additions and 53 deletions

View File

@@ -30,12 +30,17 @@ public class CosmeticBalloonType extends Cosmetic {
public void update(CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId());
user.getBalloonEntity().setLocation(player.getLocation().clone());
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));
user.getBalloonEntity().setLocation(actual);
user.getBalloonEntity().setVelocity(actual.clone().subtract(previous.clone()).toVector());
user.getBalloonEntity().updateModel();
//PacketManager.sendTeleportPacket(user.getBalloonEntity().getBalloonID(), actual, false, PlayerUtils.getNearbyPlayers(player));
//PacketManager.sendLeashPacket(user.getBalloonEntity().getBalloonID(), player.getEntityId(), PlayerUtils.getNearbyPlayers(player));
PacketManager.sendTeleportPacket(user.getBalloonEntity().getBalloonID(), actual, false, PlayerUtils.getNearbyPlayers(player));
PacketManager.sendLeashPacket(user.getBalloonEntity().getBalloonID(), player.getEntityId(), PlayerUtils.getNearbyPlayers(player));
}
public String getModelName() {

View File

@@ -14,11 +14,13 @@ import java.util.UUID;
public class BalloonEntity {
private final int balloonID;
private final UUID uniqueID;
private final MEGEntity megEntity;
public BalloonEntity(int balloonID, Location location) {
this.uniqueID = UUID.randomUUID();
this.balloonID = balloonID;
this.megEntity = new MEGEntity(UUID.randomUUID(), balloonID, new Vector(0, 0, 0), location.add(Settings.getBalloonOffset()), false);
this.megEntity = new MEGEntity(UUID.randomUUID(), balloonID, new Vector(0, 0, 0), location, false);
}
public void updateModel() {
@@ -38,10 +40,9 @@ public class BalloonEntity {
HMCCosmeticsPlugin.getInstance().getLogger().warning("Invalid Model Engine Blueprint " + id);
return;
}
HMCCosmeticsPlugin.getInstance().getLogger().warning("Possible Blueprints" + ModelEngineAPI.api.getModelRegistry().getAllBlueprintId());
//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.setRenderRadius(32);
modeledEntity.addModel(model, false);
}
@@ -54,14 +55,14 @@ public class BalloonEntity {
entity.hideFromPlayer(player);
}
ModelEngineAPI.removeModeledEntity(megEntity.getUniqueId());
//ModelEngineAPI.removeModeledEntity(megEntity.getUniqueId());
entity.destroy();
}
public void addPlayerToModel(final Player player, final String id) {
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId());
if (model == null) {
this.spawnModel(id);
spawnModel(id);
return;
}
//if (megEntity.getRangeManager().getPlayerInRange().contains(player)) return;
@@ -80,6 +81,9 @@ public class BalloonEntity {
public int getBalloonID() {
return balloonID;
}
public UUID getBalloonUUID() {
return uniqueID;
}
public UUID getUniqueID() {
return megEntity.getUniqueId();

View File

@@ -25,6 +25,7 @@ import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class MEGEntity implements BaseEntity {
@@ -45,8 +46,9 @@ public class MEGEntity implements BaseEntity {
this.alive = alive;
this.rotationController = new DefaultBodyRotationController(this);
this.passengers = new ArrayList<>();
//this.rangeManager = new EmptyRangeManager();
//this.rangeManager.setRenderDistance(32);
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) {
@@ -61,46 +63,6 @@ public class MEGEntity implements BaseEntity {
this.alive = entity.isAlive();
}
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;
}

View File

@@ -80,6 +80,7 @@ public class PlayerGameListener implements Listener {
@EventHandler
public void onPlayerLook(PlayerMoveEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (user == null) return;
// Really need to look into optimization of this
user.updateCosmetic(CosmeticSlot.BACKPACK);
user.updateCosmetic(CosmeticSlot.BALLOON);
@@ -142,13 +143,13 @@ public class PlayerGameListener implements Listener {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
@Override
public void onPacketSending(PacketEvent event) {
HMCCosmeticsPlugin.getInstance().getLogger().info("equipment packet is activated");
//HMCCosmeticsPlugin.getInstance().getLogger().info("equipment packet is activated");
Player player = event.getPlayer(); // Player that's sent
int entityID = event.getPacket().getIntegers().read(0);
// User
CosmeticUser user = CosmeticUsers.getUser(entityID);
if (user == null) {
HMCCosmeticsPlugin.getInstance().getLogger().info("equipment packet is activated - user null");
//HMCCosmeticsPlugin.getInstance().getLogger().info("equipment packet is activated - user null");
return;
}

View File

@@ -1,6 +1,7 @@
package com.hibiscusmc.hmccosmetics.user;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
@@ -10,14 +11,17 @@ 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.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.util.Vector;
@@ -166,12 +170,18 @@ public class CosmeticUser {
public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) {
Player player = Bukkit.getPlayer(getUniqueId());
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset());
if (this.balloonEntity != null) return;
BalloonEntity balloonEntity1 = new BalloonEntity(Entity.nextEntityId(), player.getLocation());
balloonEntity1.spawnModel(cosmeticBalloonType.getModelName());
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName());
balloonEntity1.updateModel();
PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getBalloonID(), EntityType.PUFFERFISH, balloonEntity1.getBalloonUUID(), sentTo);
PacketManager.sendInvisibilityPacket(balloonEntity1.getBalloonID(), sentTo);
PacketManager.sendLeashPacket(balloonEntity1.getBalloonID(), player.getEntityId(), sentTo);
this.balloonEntity = balloonEntity1;
}