OverflowBehavior enum
Пакет: com.hypixel.hytale.builtin.triggervolumes.effect.builtin
Файл: com/hypixel/hytale/builtin/triggervolumes/effect/builtin/GiveItemEffect.java
Поля (1)
| Модификаторы | Тип | Имя |
|---|---|---|
|
DROP_REMAINDER,
IGNORE_REMAINDER, |
REQUIRE_FULL_STACK |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.triggervolumes.effect.builtin;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.effect.TriggerContext;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.effect.TriggerEffect;
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.EnumCodec;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.Item;
class="kw">import com.hypixel.hytale.server.core.entity.ItemUtils;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.inventory.InventoryUtils;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
class="kw">import com.hypixel.hytale.server.core.inventory.transaction.ItemStackTransaction;
class="kw">import com.hypixel.hytale.server.core.modules.entity.player.PlayerSettings;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class GiveItemEffect class="kw">extends TriggerEffect {
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<GiveItemEffect> CODEC = BuilderCodec.builder(GiveItemEffect.class, GiveItemEffect::new, BASE_CODEC)
.append(new KeyedCodec<>("Item", Codec.STRING), (var0, var1) -> var0.itemId = var1, var0 -> var0.itemId)
.add()
.append(new KeyedCodec<>("Quantity", Codec.INTEGER, false), (var0, var1) -> var0.quantity = var1, var0 -> var0.quantity)
.add()
.append(
new KeyedCodec<>("OverflowBehavior", new EnumCodec<>(GiveItemEffect.OverflowBehavior.class), false),
(var0, var1) -> var0.overflowBehavior = var1,
var0 -> var0.overflowBehavior
)
.add()
.build();
@Nullable
class="kw">private String itemId;
class="kw">private int quantity = 1;
@Nonnull
class="kw">private GiveItemEffect.OverflowBehavior overflowBehavior = GiveItemEffect.OverflowBehavior.DROP_REMAINDER;
class="kw">public GiveItemEffect() {
}
@Override
class="kw">public void execute(@Nonnull TriggerContext var1) {
if (this.itemId != null && !this.itemId.isBlank() && this.quantity > 0) {
Store var2 = var1.getStore();
Ref var3 = var1.getEntityRef();
if (var2.getComponent(var3, Player.getComponentType()) != null) {
Item var4 = Item.getAssetMap().getAsset(this.itemId);
if (var4 != null) {
ItemStack var5 = new ItemStack(var4.getId(), this.quantity);
GiveItemEffect.OverflowBehavior var6 = this.overflowBehavior != null ? this.overflowBehavior : GiveItemEffect.OverflowBehavior.DROP_REMAINDER;
ItemStackTransaction var7 = class="kw">switch (var6) {
case DROP_REMAINDER, IGNORE_REMAINDER -> Player.giveItem(var5, var3, var2);
case REQUIRE_FULL_STACK -> {
PlayerSettings var8 = var2.getComponent(var3, PlayerSettings.getComponentType());
if (var8 == null) {
var8 = PlayerSettings.defaults();
}
ItemContainer var9 = InventoryUtils.getContainerForItemPickup(var3, var4, var8, var2);
yield var9.addItemStack(var5, true, false, true);
}
};
if (var6 == GiveItemEffect.OverflowBehavior.DROP_REMAINDER) {
ItemStack var10 = var7.getRemainder();
if (!ItemStack.isEmpty(var10)) {
ItemUtils.dropItem(var3, var10, var2);
}
}
}
}
}
}
class="kw">public enum OverflowBehavior {
DROP_REMAINDER,
IGNORE_REMAINDER,
REQUIRE_FULL_STACK;
OverflowBehavior() {
}
}
}