DeathComponent class
Пакет: com.hypixel.hytale.server.core.modules.entity.damage
Файл: com/hypixel/hytale/server/core/modules/entity/damage/DeathComponent.java
implements: Component<EntityStore>
Поля (9)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
HytaleLogger |
LOGGER |
|
DeathComponent |
var1 |
|
DeathComponent |
var2 |
|
RespawnEvent |
var3 |
|
Ref |
var3 |
|
World |
var4 |
|
Store |
var4 |
|
PlayerRef |
var5 |
|
RespawnController |
var6 |
Методы (22)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
return new |
DeathItemLossreturn new DeathItemLoss(this.itemsLossMode, this.itemsLostOnDeath, this.itemsAmountLossPercentage, this.itemsDurabilityLossPercentage) |
public |
boolean |
displayDataOnDeathScreenboolean displayDataOnDeathScreen() |
static |
ComponentType<EntityStore, DeathComponent> |
getComponentTypeComponentType<EntityStore, DeathComponent> getComponentType() |
public |
DeathItemLoss |
getDeathItemLossDeathItemLoss getDeathItemLoss() |
public |
double |
getItemsAmountLossPercentagedouble getItemsAmountLossPercentage() |
public |
double |
getItemsDurabilityLossPercentagedouble getItemsDurabilityLossPercentage() |
public |
DeathConfig.ItemsLossMode |
getItemsLossModeDeathConfig.ItemsLossMode getItemsLossMode() |
public |
ItemStack[] |
getItemsLostOnDeathItemStack[] getItemsLostOnDeath() |
|
|
if if(var2 == null) |
|
|
if if(var2.respawnFuture != null) |
|
|
if if(var2x != null) |
public |
boolean |
isShowDeathMenuboolean isShowDeathMenu() |
public |
void |
setDeathMessagevoid setDeathMessage(@Nullable Message var1) |
public |
void |
setDisplayDataOnDeathScreenvoid setDisplayDataOnDeathScreen(boolean var1) |
public |
void |
setInteractionChainvoid setInteractionChain(@Nullable InteractionChain var1) |
public |
void |
setItemsAmountLossPercentagevoid setItemsAmountLossPercentage(double var1) |
public |
void |
setItemsDurabilityLossPercentagevoid setItemsDurabilityLossPercentage(double var1) |
public |
void |
setItemsLossModevoid setItemsLossMode(DeathConfig.ItemsLossMode var1) |
public |
void |
setItemsLostOnDeathvoid setItemsLostOnDeath(List<ItemStack> var1) |
public |
void |
setShowDeathMenuvoid setShowDeathMenu(boolean var1) |
static |
void |
tryAddComponentvoid tryAddComponent(@Nonnull CommandBuffer<EntityStore> var0, @Nonnull Ref<EntityStore> var1, @Nonnull Damage var2) |
static |
void |
tryAddComponentvoid tryAddComponent(@Nonnull Store<EntityStore> var0, @Nonnull Ref<EntityStore> var1, @Nonnull Damage var2) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.entity.damage;
class="kw">import com.hypixel.hytale.assetstore.AssetRegistry;
class="kw">import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Component;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.type.gameplay.DeathConfig;
class="kw">import com.hypixel.hytale.server.core.asset.type.gameplay.respawn.RespawnController;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionChain;
class="kw">import com.hypixel.hytale.server.core.event.events.ecs.RespawnEvent;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.List;
class="kw">import java.util.concurrent.CompletableFuture;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class DeathComponent class="kw">implements Component<EntityStore> {
class="kw">public class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
class="kw">public class="kw">static class="kw">final BuilderCodec<DeathComponent> CODEC = BuilderCodec.builder(DeathComponent.class, DeathComponent::new)
.append(new KeyedCodec<>("DeathCause", Codec.STRING), (var0, var1) -> var0.deathCause = var1, var0 -> var0.deathCause)
.add()
.append(new KeyedCodec<>("DeathMessage", Message.CODEC), (var0, var1) -> var0.deathMessage = var1, var0 -> var0.deathMessage)
.add()
.append(new KeyedCodec<>("ShowDeathMenu", BuilderCodec.BOOLEAN), (var0, var1) -> var0.showDeathMenu = var1, var0 -> var0.showDeathMenu)
.add()
.append(
new KeyedCodec<>("ItemsLostOnDeath", new ArrayCodec<>(ItemStack.CODEC, ItemStack[]::new)),
(var0, var1) -> var0.itemsLostOnDeath = var1,
var0 -> var0.itemsLostOnDeath
)
.add()
.append(
new KeyedCodec<>("ItemsAmountLossPercentage", Codec.DOUBLE),
(var0, var1) -> var0.itemsAmountLossPercentage = var1,
var0 -> var0.itemsAmountLossPercentage
)
.add()
.append(
new KeyedCodec<>("ItemsDurabilityLossPercentage", Codec.DOUBLE),
(var0, var1) -> var0.itemsDurabilityLossPercentage = var1,
var0 -> var0.itemsDurabilityLossPercentage
)
.add()
.append(
new KeyedCodec<>("DisplayDataOnDeathScreen", Codec.BOOLEAN),
(var0, var1) -> var0.displayDataOnDeathScreen = var1,
var0 -> var0.displayDataOnDeathScreen
)
.add()
.build();
class="kw">private String deathCause;
@Nullable
class="kw">private Message deathMessage;
class="kw">private boolean showDeathMenu = true;
class="kw">private ItemStack[] itemsLostOnDeath;
class="kw">private double itemsAmountLossPercentage;
class="kw">private double itemsDurabilityLossPercentage;
class="kw">private boolean displayDataOnDeathScreen;
@Nullable
class="kw">private class="kw">transient Damage deathInfo;
class="kw">private class="kw">transient DeathConfig.ItemsLossMode itemsLossMode = DeathConfig.ItemsLossMode.ALL;
@Nullable
class="kw">private class="kw">transient InteractionChain interactionChain;
class="kw">private class="kw">transient CompletableFuture<Void> respawnFuture = null;
class="kw">public class="kw">static ComponentType<EntityStore, DeathComponent> getComponentType() {
class="kw">return DamageModule.get().getDeathComponentType();
}
class="kw">protected DeathComponent(@Nonnull Damage var1) {
this.deathInfo = var1;
this.deathCause = var1.getCause().getId();
}
class="kw">protected DeathComponent() {
}
@Nullable
class="kw">public DamageCause getDeathCause() {
class="kw">return (DamageCause)((IndexedLookupTableAssetMap)AssetRegistry.getAssetStore(DamageCause.class).getAssetMap()).getAsset(this.deathCause);
}
@Nullable
class="kw">public Message getDeathMessage() {
class="kw">return this.deathMessage;
}
class="kw">public void setDeathMessage(@Nullable Message var1) {
this.deathMessage = var1;
}
class="kw">public boolean isShowDeathMenu() {
class="kw">return this.showDeathMenu;
}
class="kw">public void setShowDeathMenu(boolean var1) {
this.showDeathMenu = var1;
}
class="kw">public ItemStack[] getItemsLostOnDeath() {
class="kw">return this.itemsLostOnDeath;
}
class="kw">public void setItemsLostOnDeath(List<ItemStack> var1) {
this.itemsLostOnDeath = var1.toArray(ItemStack[]::new);
}
class="kw">public double getItemsAmountLossPercentage() {
class="kw">return this.itemsAmountLossPercentage;
}
class="kw">public void setItemsAmountLossPercentage(double var1) {
this.itemsAmountLossPercentage = var1;
}
class="kw">public double getItemsDurabilityLossPercentage() {
class="kw">return this.itemsDurabilityLossPercentage;
}
class="kw">public void setItemsDurabilityLossPercentage(double var1) {
this.itemsDurabilityLossPercentage = var1;
}
class="kw">public boolean displayDataOnDeathScreen() {
class="kw">return this.displayDataOnDeathScreen;
}
class="kw">public void setDisplayDataOnDeathScreen(boolean var1) {
this.displayDataOnDeathScreen = var1;
}
@Nullable
class="kw">public Damage getDeathInfo() {
class="kw">return this.deathInfo;
}
class="kw">public DeathConfig.ItemsLossMode getItemsLossMode() {
class="kw">return this.itemsLossMode;
}
class="kw">public void setItemsLossMode(DeathConfig.ItemsLossMode var1) {
this.itemsLossMode = var1;
}
class="kw">public DeathItemLoss getDeathItemLoss() {
class="kw">return new DeathItemLoss(this.itemsLossMode, this.itemsLostOnDeath, this.itemsAmountLossPercentage, this.itemsDurabilityLossPercentage);
}
@Nullable
class="kw">public InteractionChain getInteractionChain() {
class="kw">return this.interactionChain;
}
class="kw">public void setInteractionChain(@Nullable InteractionChain var1) {
this.interactionChain = var1;
}
@Nonnull
@Override
class="kw">public Component<EntityStore> clone() {
DeathComponent var1 = new DeathComponent();
var1.deathCause = this.deathCause;
var1.deathMessage = this.deathMessage;
var1.showDeathMenu = this.showDeathMenu;
var1.itemsLostOnDeath = this.itemsLostOnDeath;
var1.itemsAmountLossPercentage = this.itemsAmountLossPercentage;
var1.itemsDurabilityLossPercentage = this.itemsDurabilityLossPercentage;
var1.displayDataOnDeathScreen = this.displayDataOnDeathScreen;
var1.deathInfo = this.deathInfo;
var1.itemsLossMode = this.itemsLossMode;
class="kw">return var1;
}
class="kw">public class="kw">static void tryAddComponent(@Nonnull CommandBuffer<EntityStore> var0, @Nonnull Ref<EntityStore> var1, @Nonnull Damage var2) {
if (!var0.getArchetype(var1).contains(getComponentType())) {
var0.run(var2x -> tryAddComponent(var2x, var1, var2));
}
}
class="kw">public class="kw">static void tryAddComponent(@Nonnull Store<EntityStore> var0, @Nonnull Ref<EntityStore> var1, @Nonnull Damage var2) {
if (!var0.getArchetype(var1).contains(getComponentType())) {
var0.addComponent(var1, getComponentType(), new DeathComponent(var2));
}
}
@Nullable
class="kw">public class="kw">static CompletableFuture<Void> respawn(@Nonnull ComponentAccessor<EntityStore> var0, @Nonnull Ref<EntityStore> var1) {
DeathComponent var2 = var0.getComponent(var1, getComponentType());
if (var2 == null) {
class="kw">return CompletableFuture.completedFuture(null);
}
if (var2.respawnFuture != null) {
class="kw">return var2.respawnFuture;
}
RespawnEvent var3 = new RespawnEvent();
var0.invoke(var1, var3);
if (var3.isCancelled()) {
class="kw">return null;
}
World var4 = var0.getExternalData().getWorld();
PlayerRef var5 = var0.getComponent(var1, PlayerRef.getComponentType());
RespawnController var6 = var4.getDeathConfig().getRespawnController();
var2.respawnFuture = var6.respawnPlayer(var4, var1, var0).whenComplete((var1x, var2x) -> {
if (var2x != null) {
((HytaleLogger.Api)((HytaleLogger.Api)LOGGER.atSevere()).withCause(var2x)).log("Failed to respawn entity");
}
Ref var3 = var5.getReference();
if (var3 != null && var3.isValid()) {
Store var4 = var3.getStore();
var4.tryRemoveComponent(var3, getComponentType());
}
});
class="kw">return var2.respawnFuture;
}
}