mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 12:29:16 +00:00
feat: backpack improvements
This commit is contained in:
@@ -2,6 +2,8 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -12,11 +14,13 @@ import org.spongepowered.configurate.ConfigurationNode;
|
||||
public class CosmeticBackpackType extends Cosmetic {
|
||||
|
||||
private final String modelName;
|
||||
private UserBackpackManager.BackpackType backpackType;
|
||||
|
||||
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
modelName = config.node("model").getString();
|
||||
backpackType = UserBackpackManager.BackpackType.valueOf(config.node("type").getString("NORMAL").toUpperCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,7 +37,13 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
|
||||
user.getUserBackpackManager().getArmorStand().teleport(loc);
|
||||
|
||||
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
|
||||
if (user.getUserBackpackManager().getBackpackType().equals(UserBackpackManager.BackpackType.FIRST_PERSON)) {
|
||||
user.getUserBackpackManager().teleportEffectEntity(loc);
|
||||
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc);
|
||||
PacketManager.sendRidingPacket(user.getUserBackpackManager().getAreaEffectEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
|
||||
} else {
|
||||
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
|
||||
}
|
||||
|
||||
user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch());
|
||||
user.getUserBackpackManager().showBackpack();
|
||||
@@ -42,4 +52,8 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
public String getModelName() {
|
||||
return modelName;
|
||||
}
|
||||
|
||||
public UserBackpackManager.BackpackType getBackpackType() {
|
||||
return backpackType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ public class CosmeticUser {
|
||||
|
||||
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||
if (this.userBackpackManager != null) return;
|
||||
this.userBackpackManager = new UserBackpackManager(this);
|
||||
this.userBackpackManager = new UserBackpackManager(this, cosmeticBackpackType.getBackpackType());
|
||||
userBackpackManager.spawnBackpack(cosmeticBackpackType);
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ public class CosmeticUser {
|
||||
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), -1, viewer);
|
||||
}
|
||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
userBackpackManager.getArmorStand().getEquipment().clear();
|
||||
userBackpackManager.clearItems();
|
||||
}
|
||||
updateCosmetic();
|
||||
MessagesUtil.sendDebugMessages("HideCosmetics");
|
||||
@@ -431,7 +431,7 @@ public class CosmeticUser {
|
||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
|
||||
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
|
||||
userBackpackManager.getArmorStand().getEquipment().setHelmet(item);
|
||||
userBackpackManager.setItem(item);
|
||||
}
|
||||
updateCosmetic();
|
||||
MessagesUtil.sendDebugMessages("ShowCosmetics");
|
||||
|
||||
@@ -9,6 +9,9 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -18,13 +21,14 @@ public class UserBackpackManager {
|
||||
|
||||
private boolean hideBackpack;
|
||||
private ArmorStand invisibleArmorStand;
|
||||
private AreaEffectCloud particleCloud;
|
||||
private final CosmeticUser user;
|
||||
private BackpackType backpackType;
|
||||
|
||||
public UserBackpackManager(CosmeticUser user) {
|
||||
public UserBackpackManager(CosmeticUser user, BackpackType backpackType) {
|
||||
this.user = user;
|
||||
hideBackpack = false;
|
||||
backpackType = BackpackType.NORMAL;
|
||||
this.backpackType = backpackType;
|
||||
}
|
||||
|
||||
public int getFirstArmorStandId() {
|
||||
@@ -38,6 +42,16 @@ public class UserBackpackManager {
|
||||
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start");
|
||||
|
||||
if (getBackpackType().equals(BackpackType.NORMAL)) {
|
||||
spawnNormalBackpack(cosmeticBackpackType);
|
||||
}
|
||||
if (getBackpackType().equals(BackpackType.FIRST_PERSON)) {
|
||||
spawnFirstPersonBackpack(cosmeticBackpackType);
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnNormalBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||
|
||||
if (this.invisibleArmorStand != null) return;
|
||||
|
||||
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
|
||||
@@ -56,11 +70,37 @@ public class UserBackpackManager {
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
|
||||
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
||||
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
|
||||
return;
|
||||
}
|
||||
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
|
||||
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
|
||||
model.setCanHurt(false);
|
||||
modeledEntity.addModel(model, false);
|
||||
}
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
|
||||
}
|
||||
|
||||
public void despawnBackpack() {
|
||||
if (invisibleArmorStand == null) return;
|
||||
invisibleArmorStand.setHealth(0);
|
||||
invisibleArmorStand.remove();
|
||||
this.invisibleArmorStand = null;
|
||||
if (invisibleArmorStand != null) {
|
||||
invisibleArmorStand.setHealth(0);
|
||||
invisibleArmorStand.remove();
|
||||
this.invisibleArmorStand = null;
|
||||
}
|
||||
if (particleCloud != null) {
|
||||
particleCloud.remove();
|
||||
this.particleCloud = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void hideBackpack() {
|
||||
@@ -81,6 +121,27 @@ public class UserBackpackManager {
|
||||
hideBackpack = shown;
|
||||
}
|
||||
|
||||
public BackpackType getBackpackType() {
|
||||
return backpackType;
|
||||
}
|
||||
|
||||
public int getAreaEffectEntityId() {
|
||||
return particleCloud.getEntityId();
|
||||
}
|
||||
|
||||
public void teleportEffectEntity(Location location) {
|
||||
particleCloud.teleport(location);
|
||||
}
|
||||
|
||||
public void setItem(ItemStack item) {
|
||||
getArmorStand().getEquipment().setHelmet(item);
|
||||
}
|
||||
|
||||
public void clearItems() {
|
||||
ItemStack item = new ItemStack(Material.AIR);
|
||||
getArmorStand().getEquipment().setHelmet(item);
|
||||
}
|
||||
|
||||
public enum BackpackType {
|
||||
NORMAL,
|
||||
FIRST_PERSON // First person not yet implemented
|
||||
|
||||
Reference in New Issue
Block a user