ItemUtils class
Пакет: com.hypixel.hytale.server.core.entity
Файл: com/hypixel/hytale/server/core/entity/ItemUtils.java
Поля (32)
| Модификаторы | Тип | Имя |
|---|---|---|
|
|
var1 |
|
|
var1 |
|
ItemStack |
var10 |
|
int |
var10 |
|
CombinedItemContainer |
var12 |
|
|
var2 |
|
Player |
var2 |
|
Player |
var2 |
|
InteractivelyPickupItemEvent |
var4 |
|
DropItemEvent.Drop |
var4 |
|
Player |
var5 |
|
HeadRotation |
var5 |
|
TransformComponent |
var5 |
|
Item |
var5 |
|
Holder |
var6 |
|
|
var6 |
|
|
var6 |
|
Rotation3f |
var6 |
|
float |
var6 |
|
ItemContainer |
var6 |
|
ItemStackTransaction |
var7 |
|
Vector3d |
var7 |
|
Vector3d |
var7 |
|
ItemStack |
var7 |
|
ItemStackSlotTransaction |
var7 |
|
ItemStack |
var8 |
|
Holder |
var8 |
|
ItemStackSlotTransaction |
var8 |
|
EntityStatMap |
var8 |
|
int |
var9 |
|
ItemComponent |
var9 |
|
PlayerRef |
var9 |
Методы (18)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
static |
boolean |
canApplyItemStackPenaltiesboolean canApplyItemStackPenalties(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) |
static |
boolean |
canDecreaseItemStackDurabilityboolean canDecreaseItemStackDurability(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) |
abstract |
|
dropItem dropItem(var0, var8, var3) |
|
|
if if(var5 != null) |
|
|
if if(var9 > 0) |
|
|
if if(var10 != null) |
|
|
if if(var2 != null) |
|
|
if if(var2 != null) |
|
|
if if(var6 != null) |
|
|
if if(var5 == null) |
|
|
if if(var8 == null) |
|
|
if if(var9 != null) |
|
|
if if(var9 != null) |
|
|
if if(var6 == null) |
|
|
if if(var8 != null) |
static |
void |
interactivelyPickupItemvoid interactivelyPickupItem(@Nonnull Ref<EntityStore> var0, @Nonnull ItemStack var1, @Nullable Vector3d var2, @Nonnull ComponentAccessor<EntityStore> var3) |
abstract |
return |
throwItemreturn throwItem(var0, var3, var1, var7, var2) |
abstract |
return |
throwItemreturn throwItem(var0, var1, 1.0F, var2) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.entity;
class="kw">import com.hypixel.hytale.component.AddReason;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Holder;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.math.vector.Transform;
class="kw">import com.hypixel.hytale.protocol.GameMode;
class="kw">import com.hypixel.hytale.protocol.SoundCategory;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.Item;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.event.events.ecs.DropItemEvent;
class="kw">import com.hypixel.hytale.server.core.event.events.ecs.InteractivelyPickupItemEvent;
class="kw">import com.hypixel.hytale.server.core.inventory.InventoryComponent;
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.CombinedItemContainer;
class="kw">import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
class="kw">import com.hypixel.hytale.server.core.inventory.container.SimpleItemContainer;
class="kw">import com.hypixel.hytale.server.core.inventory.transaction.ItemStackSlotTransaction;
class="kw">import com.hypixel.hytale.server.core.inventory.transaction.ItemStackTransaction;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.item.ItemComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entitystats.EntityStatMap;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.SoundUtil;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.core.util.TempAssetIdUtil;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">public class ItemUtils {
@Nonnull
class="kw">public class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
class="kw">public ItemUtils() {
}
class="kw">public class="kw">static void interactivelyPickupItem(
@Nonnull Ref<EntityStore> var0, @Nonnull ItemStack var1, @Nullable Vector3d var2, @Nonnull ComponentAccessor<EntityStore> var3
) {
InteractivelyPickupItemEvent var4 = new InteractivelyPickupItemEvent(var1);
var3.invoke(var0, var4);
if (!var4.isCancelled()) {
var1 = var4.getItemStack();
Player var5 = var3.getComponent(var0, Player.getComponentType());
if (var5 != null) {
Holder var6 = null;
ItemStackTransaction var7 = Player.giveItem(var1, var0, var3);
ItemStack var8 = var7.getRemainder();
if (var8 != null && !var8.isEmpty()) {
int var9 = var1.getQuantity() - var8.getQuantity();
if (var9 > 0) {
ItemStack var10 = var1.withQuantity(var9);
if (var10 != null) {
Player.notifyPickupItem(var0, var10, null, var3);
if (var2 != null) {
var6 = ItemComponent.generatePickedUpItem(var10, var2, var3, var0);
}
}
}
dropItem(var0, var8, var3);
} else {
Player.notifyPickupItem(var0, var1, null, var3);
if (var2 != null) {
var6 = ItemComponent.generatePickedUpItem(var1, var2, var3, var0);
}
}
if (var6 != null) {
var3.addEntity(var6, AddReason.SPAWN);
}
} else {
CombinedItemContainer var12 = InventoryComponent.getCombined(var3, var0, InventoryComponent.HOTBAR_FIRST);
SimpleItemContainer.addOrDropItemStack(var3, var0, var12, var1);
}
}
}
@Nullable
class="kw">public class="kw">static Ref<EntityStore> throwItem(@Nonnull Ref<EntityStore> var0, @Nonnull ItemStack var1, float var2, @Nonnull ComponentAccessor<EntityStore> var3) {
DropItemEvent.Drop var4 = new DropItemEvent.Drop(var1, var2);
var3.invoke(var0, var4);
if (var4.isCancelled()) {
class="kw">return null;
} else {
var2 = var4.getThrowSpeed();
var1 = var4.getItemStack();
if (!var1.isEmpty() && var1.isValid()) {
HeadRotation var5 = var3.getComponent(var0, HeadRotation.getComponentType());
Rotation3f var6 = var5 != null ? var5.getRotation() : new Rotation3f(0.0F, 0.0F, 0.0F);
Vector3d var7 = Transform.getDirection(var6.pitch(), var6.yaw());
class="kw">return throwItem(var0, var3, var1, var7, var2);
} else {
LOGGER.at(Level.WARNING).log("Attempted to throw invalid item %s at %s by %s", var1, var2, var0.getIndex());
class="kw">return null;
}
}
}
@Nullable
class="kw">public class="kw">static Ref<EntityStore> throwItem(
@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull ItemStack var2, @Nonnull Vector3d var3, float var4
) {
if (!var0.isValid()) {
LOGGER.at(Level.WARNING).log("Attempted to throw item %s by invalid entity %s", var2, var0.getIndex());
class="kw">return null;
}
TransformComponent var5 = var1.getComponent(var0, TransformComponent.getComponentType());
if (var5 == null) {
LOGGER.at(Level.WARNING).log("Attempted to throw item %s by entity %s without a TransformComponent", var2, var0.getIndex());
class="kw">return null;
}
float var6 = ModelComponent.getEyeHeight(var0, var1);
Vector3d var7 = new Vector3d(var5.getPosition());
var7.add(0.0, var6, 0.0).add(var3);
Holder var8 = ItemComponent.generateItemDrop(var1, var2, var7, Rotation3f.IDENTITY, (float)var3.x * var4, (float)var3.y * var4, (float)var3.z * var4);
if (var8 == null) {
class="kw">return null;
}
ItemComponent var9 = var8.getComponent(ItemComponent.getComponentType());
if (var9 != null) {
var9.setPickupDelay(1.5F);
}
class="kw">return var1.addEntity(var8, AddReason.SPAWN);
}
@Nullable
class="kw">public class="kw">static Ref<EntityStore> dropItem(@Nonnull Ref<EntityStore> var0, @Nonnull ItemStack var1, @Nonnull ComponentAccessor<EntityStore> var2) {
class="kw">return throwItem(var0, var1, 1.0F, var2);
}
class="kw">public class="kw">static boolean canDecreaseItemStackDurability(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) {
Player var2 = var1.getComponent(var0, Player.getComponentType());
class="kw">return var2 != null ? var2.getGameMode() != GameMode.Creative : false;
}
class="kw">public class="kw">static boolean canApplyItemStackPenalties(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) {
Player var2 = var1.getComponent(var0, Player.getComponentType());
class="kw">return var2 != null ? var2.getGameMode() != GameMode.Creative : true;
}
@Nonnull
class="kw">public class="kw">static ItemStackSlotTransaction updateItemStackDurability(
@Nonnull Ref<EntityStore> var0, @Nonnull ItemStack var1, ItemContainer var2, int var3, double var4, @Nonnull ComponentAccessor<EntityStore> var6
) {
ItemStack var7 = var1.withIncreasedDurability(var4);
ItemStackSlotTransaction var8 = var2.replaceItemStackInSlot((short)var3, var1, var7);
if (var8.getSlotAfter().isBroken() && !var1.isBroken()) {
PlayerRef var9 = var6.getComponent(var0, PlayerRef.getComponentType());
if (var9 != null) {
var9.sendMessage(Message.translation("server.general.repair.itemBroken").param("itemName", var1.getDisplayName()).color("#ff5555"));
int var10 = TempAssetIdUtil.getSoundEventIndex("SFX_Item_Break");
SoundUtil.playSoundEvent2dToPlayer(var9, var10, SoundCategory.UI);
}
}
class="kw">return var8;
}
@Nullable
class="kw">public class="kw">static ItemStackSlotTransaction decreaseItemStackDurability(
@Nonnull Ref<EntityStore> var0, @Nullable ItemStack var1, int var2, int var3, @Nonnull ComponentAccessor<EntityStore> var4
) {
if (!canDecreaseItemStackDurability(var0, var4)) {
class="kw">return null;
}
if (var1 == null || var1.isEmpty() || var1.getItem() == Item.UNKNOWN) {
class="kw">return null;
}
if (var1.isBroken()) {
class="kw">return null;
}
Item var5 = var1.getItem();
ItemContainer var6 = InventoryUtils.getSectionById(var0, var2, var4);
if (var6 == null) {
class="kw">return null;
}
if (var5.getArmor() != null) {
ItemStackSlotTransaction var7 = updateItemStackDurability(var0, var1, var6, var3, -var5.getDurabilityLossOnHit(), var4);
if (var7.getSlotAfter().isBroken()) {
EntityStatMap var8 = var4.getComponent(var0, EntityStatMap.getComponentType());
if (var8 != null) {
var8.getStatModifiersManager().scheduleRecalculate();
}
}
class="kw">return var7;
} else {
class="kw">return var5.getWeapon() != null ? updateItemStackDurability(var0, var1, var6, var3, -var5.getDurabilityLossOnHit(), var4) : null;
}
}
}