mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 20:39:13 +00:00
feat: first iteration of first-person backpacks
This commit is contained in:
@@ -7,10 +7,12 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CosmeticBackpackType extends Cosmetic {
|
||||
@@ -45,9 +47,19 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
user.getUserBackpackManager().getArmorStand().teleport(loc);
|
||||
|
||||
if (user.getUserBackpackManager().getBackpackType().equals(UserBackpackManager.BackpackType.FIRST_PERSON)) {
|
||||
user.getUserBackpackManager().teleportEffectEntity(loc);
|
||||
PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc);
|
||||
PacketManager.sendRidingPacket(user.getUserBackpackManager().getAreaEffectEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
|
||||
ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
|
||||
for (int i = 0; i < particleCloud.size(); i++) {
|
||||
//particleCloud.get(i).teleport(loc);
|
||||
if (i == 0) {
|
||||
PacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), loc);
|
||||
} else {
|
||||
PacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , loc);
|
||||
}
|
||||
MessagesUtil.sendDebugMessages("num: " + i + " / valid? ");
|
||||
}
|
||||
//PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc);
|
||||
PacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), loc);
|
||||
MessagesUtil.sendDebugMessages("ParticleCloud: " + particleCloud.toString());
|
||||
} else {
|
||||
PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
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;
|
||||
@@ -14,21 +15,24 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class UserBackpackManager {
|
||||
|
||||
private boolean hideBackpack;
|
||||
private ArmorStand invisibleArmorStand;
|
||||
private AreaEffectCloud particleCloud;
|
||||
private ArrayList<Integer> particleCloud = new ArrayList<>();
|
||||
private final CosmeticUser user;
|
||||
private BackpackType backpackType;
|
||||
|
||||
public UserBackpackManager(CosmeticUser user, BackpackType backpackType) {
|
||||
this.user = user;
|
||||
hideBackpack = false;
|
||||
this.hideBackpack = false;
|
||||
this.backpackType = backpackType;
|
||||
}
|
||||
|
||||
@@ -80,12 +84,19 @@ public class UserBackpackManager {
|
||||
}
|
||||
|
||||
public void spawnFirstPersonBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||
|
||||
if (this.invisibleArmorStand != null) return;
|
||||
|
||||
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
|
||||
this.particleCloud = (AreaEffectCloud) NMSHandlers.getHandler().spawnHMCParticleCloud(user.getPlayer().getLocation());
|
||||
for (int i = particleCloud.size(); i < 5; i++) {
|
||||
int entityId = NMSHandlers.getHandler().getNextEntityId();
|
||||
PacketManager.sendEntitySpawnPacket(user.getPlayer().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
|
||||
PacketManager.sendCloudEffect(entityId, PacketManager.getViewers(user.getPlayer().getLocation()));
|
||||
this.particleCloud.add(entityId);
|
||||
//this.particleCloud.add((AreaEffectCloud) NMSHandlers.getHandler().spawnHMCParticleCloud(user.getPlayer().getLocation()));
|
||||
}
|
||||
//this.particleCloud = (AreaEffectCloud) NMSHandlers.getHandler().spawnHMCParticleCloud(user.getPlayer().getLocation());
|
||||
|
||||
/*
|
||||
if (cosmeticBackpackType.getModelName() != null && Hooks.isActiveHook("ModelEngine")) {
|
||||
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
||||
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
|
||||
@@ -96,8 +107,9 @@ public class UserBackpackManager {
|
||||
model.setCanHurt(false);
|
||||
modeledEntity.addModel(model, false);
|
||||
}
|
||||
*/
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
|
||||
MessagesUtil.sendDebugMessages("spawnBackpackFirstPerson Bukkit - Finish");
|
||||
}
|
||||
|
||||
public void despawnBackpack() {
|
||||
@@ -107,7 +119,9 @@ public class UserBackpackManager {
|
||||
this.invisibleArmorStand = null;
|
||||
}
|
||||
if (particleCloud != null) {
|
||||
particleCloud.remove();
|
||||
for (int i = 0; i < particleCloud.size(); i++) {
|
||||
//particleCloud.get(i).remove();
|
||||
}
|
||||
this.particleCloud = null;
|
||||
}
|
||||
}
|
||||
@@ -134,12 +148,8 @@ public class UserBackpackManager {
|
||||
return backpackType;
|
||||
}
|
||||
|
||||
public int getAreaEffectEntityId() {
|
||||
return particleCloud.getEntityId();
|
||||
}
|
||||
|
||||
public void teleportEffectEntity(Location location) {
|
||||
particleCloud.teleport(location);
|
||||
public ArrayList<Integer> getAreaEffectEntityId() {
|
||||
return particleCloud;
|
||||
}
|
||||
|
||||
public void setItem(ItemStack item) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEnt
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -31,6 +32,15 @@ import java.util.UUID;
|
||||
|
||||
public class PacketManager extends BasePacket {
|
||||
|
||||
public static void sendEntitySpawnPacket(
|
||||
final @NotNull Location location,
|
||||
final int entityId,
|
||||
final EntityType entityType,
|
||||
final UUID uuid
|
||||
) {
|
||||
sendEntitySpawnPacket(location, entityId, entityType, uuid, getViewers(location));
|
||||
}
|
||||
|
||||
public static void sendEntitySpawnPacket(
|
||||
final @NotNull Location location,
|
||||
final int entityId,
|
||||
@@ -145,7 +155,29 @@ public class PacketManager extends BasePacket {
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
}
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendCloudEffect(
|
||||
int entityId,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entityId);
|
||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||
|
||||
if (NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(8, WrappedDataWatcher.Registry.get(Float.class)), 0f);
|
||||
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
|
||||
} else {
|
||||
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
|
||||
wrappedDataValueList.add(new WrappedDataValue(8, WrappedDataWatcher.Registry.get(Float.class), 0f));
|
||||
//wrappedDataValueList.add(new WrappedDataValue(11, WrappedDataWatcher.Registry.get(Integer.class), 21));
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
}
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendLookPacket(
|
||||
|
||||
Reference in New Issue
Block a user