UseCaptureCrateInteraction class
Пакет: com.hypixel.hytale.builtin.adventure.farming.interactions
Файл: com/hypixel/hytale/builtin/adventure/farming/interactions/UseCaptureCrateInteraction.java
extends: SimpleBlockInteraction
Поля (49)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
HytaleLogger |
LOGGER |
|
|
break |
|
|
return |
|
byte |
var10 |
|
InventoryComponent.Hotbar |
var10 |
|
ItemStack |
var11 |
|
byte |
var11 |
|
CapturedNPCMetadata |
var12 |
|
CapturedNPCMetadata |
var12 |
|
Ref |
var13 |
|
BlockPosition |
var13 |
|
NPCEntity |
var14 |
|
Store |
var14 |
|
DeathComponent |
var15 |
|
Ref |
var15 |
|
TagSetPlugin.TagSetLookup |
var16 |
|
BlockSection |
var16 |
|
boolean |
var17 |
|
|
var17 |
|
BlockComponentSection |
var17 |
|
int |
var18 |
|
Ref |
var19 |
|
|
var19 |
|
int |
var2 |
|
BlockType |
var20 |
|
CoopBlock |
var21 |
|
Role |
var22 |
|
BlockFace |
var22 |
|
String |
var23 |
|
Vector3ic |
var23 |
|
ModelAsset |
var24 |
|
AlarmStore |
var24 |
|
String |
var25 |
|
ItemStack |
var25 |
|
PersistentModel |
var26 |
|
Vector3d |
var26 |
|
ModelAsset |
var27 |
|
String |
var27 |
|
CapturedNPCMetadata |
var28 |
|
WorldTimeResource |
var28 |
|
String |
var29 |
|
int |
var29 |
|
ItemStack |
var30 |
|
CommandBuffer |
var6 |
|
ItemStack |
var7 |
|
Ref |
var8 |
|
ItemStack |
var8 |
|
InventoryComponent.Hotbar |
var9 |
|
Ref |
var9 |
Методы (25)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
for for(int var1 = 0; var1 < var0.acceptedNpcGroupIds.length; var1++) |
|
|
for for(int var21 : this.acceptedNpcGroupIndexes) |
|
|
if if(var0.acceptedNpcGroupIds != null) |
|
|
if if(var7 == null) |
|
|
if if(var9 == null) |
|
|
if if(var11 == null) |
|
|
if if(var12 != null) |
|
|
if if(var13 == null) |
|
|
if if(var14 == null) |
|
|
if if(var15 != null) |
|
|
if if(!var17) |
|
|
if if(var26 == null) |
|
|
if if(var27 != null) |
|
|
if if(var29 != null) |
|
|
if if(var22 != null) |
|
|
if if(var24 == null) |
|
|
if if(var25 != null) |
|
|
if if(var8 == null) |
|
|
if if(var10 == null) |
|
|
if if(var12 == null) |
|
|
if if(var13 == null) |
|
|
if if(var16 != null && var17 != null) |
|
|
if if(var21 != null) |
|
|
if if(var22 != null) |
|
|
if if(var24 != null) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.adventure.farming.interactions;
class="kw">import com.hypixel.hytale.builtin.adventure.farming.states.CoopBlock;
class="kw">import com.hypixel.hytale.builtin.tagset.TagSetPlugin;
class="kw">import com.hypixel.hytale.builtin.tagset.config.NPCGroup;
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.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.RemoveReason;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.math.vector.Vector3dUtil;
class="kw">import com.hypixel.hytale.protocol.BlockPosition;
class="kw">import com.hypixel.hytale.protocol.InteractionState;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
class="kw">import com.hypixel.hytale.server.core.entity.EntityUtils;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.inventory.InventoryComponent;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.modules.block.BlockEntity;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.PersistentModel;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInteraction;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.client.SimpleBlockInteraction;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.util.InteractionValidation;
class="kw">import com.hypixel.hytale.server.core.modules.time.WorldTimeResource;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockComponentSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.NPCPlugin;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.metadata.CapturedNPCMetadata;
class="kw">import com.hypixel.hytale.server.npc.role.Role;
class="kw">import com.hypixel.hytale.server.npc.storage.AlarmStore;
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">import org.joml.Vector3i;
class="kw">import org.joml.Vector3ic;
class="kw">public class UseCaptureCrateInteraction class="kw">extends SimpleBlockInteraction {
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<UseCaptureCrateInteraction> CODEC = BuilderCodec.builder(
UseCaptureCrateInteraction.class, UseCaptureCrateInteraction::new, SimpleInteraction.CODEC
)
.appendInherited(
new KeyedCodec<>("AcceptedNpcGroups", NPCGroup.CHILD_ASSET_CODEC_ARRAY),
(var0, var1) -> var0.acceptedNpcGroupIds = var1,
var0 -> var0.acceptedNpcGroupIds,
(var0, var1) -> var0.acceptedNpcGroupIds = var1.acceptedNpcGroupIds
)
.addValidator(NPCGroup.VALIDATOR_CACHE.getArrayValidator())
.add()
.appendInherited(
new KeyedCodec<>("FullIcon", Codec.STRING), (var0, var1) -> var0.fullIcon = var1, var0 -> var0.fullIcon, (var0, var1) -> var0.fullIcon = var1.fullIcon
)
.add()
.afterDecode(var0 -> {
if (var0.acceptedNpcGroupIds != null) {
var0.acceptedNpcGroupIndexes = new int[var0.acceptedNpcGroupIds.length];
for (int var1 = 0; var1 < var0.acceptedNpcGroupIds.length; var1++) {
int var2 = NPCGroup.getAssetMap().getIndex(var0.acceptedNpcGroupIds[var1]);
var0.acceptedNpcGroupIndexes[var1] = var2;
}
}
})
.build();
class="kw">protected String[] acceptedNpcGroupIds;
class="kw">protected int[] acceptedNpcGroupIndexes;
class="kw">protected String fullIcon;
class="kw">public UseCaptureCrateInteraction() {
}
@Override
class="kw">protected void tick0(boolean var1, float var2, @Nonnull InteractionType var3, @Nonnull InteractionContext var4, @Nonnull CooldownHandler var5) {
CommandBuffer var6 = var4.getCommandBuffer();
assert var6 != null;
ItemStack var7 = var4.getHeldItem();
if (var7 == null) {
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else {
Ref var8 = var4.getEntity();
InventoryComponent.Hotbar var9 = var6.getComponent(var8, InventoryComponent.Hotbar.getComponentType());
if (var9 == null) {
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else {
byte var10 = var9.getActiveSlot();
ItemStack var11 = var9.getActiveItem();
if (var11 == null) {
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else {
CapturedNPCMetadata var12 = var7.getFromMetadataOrNull("CapturedEntity", CapturedNPCMetadata.CODEC);
if (var12 != null) {
super.tick0(var1, var2, var3, var4, var5);
} else {
Ref var13 = var4.getTargetEntity();
if (var13 == null) {
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else {
NPCEntity var14 = var6.getComponent(var13, NPCEntity.getComponentType());
if (var14 == null) {
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else {
DeathComponent var15 = var6.getComponent(var13, DeathComponent.getComponentType());
if (var15 != null) {
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else {
TagSetPlugin.TagSetLookup var16 = TagSetPlugin.get(NPCGroup.class);
boolean var17 = false;
for (int var21 : this.acceptedNpcGroupIndexes) {
if (var16.tagInSet(var21, var14.getRoleIndex())) {
var17 = true;
break;
}
}
if (!var17) {
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else if (!InteractionValidation.canPlayerInteractWithEntity(var8, var6, var4.getHeldItem(), var13)) {
LOGGER.at(Level.WARNING)
.log(
"%s failed capture crate interaction distance check for target entity %d",
EntityUtils.getEntityName(var8, var6),
var13.getIndex()
);
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else {
PersistentModel var26 = var6.getComponent(var13, PersistentModel.getComponentType());
if (var26 == null) {
var4.getState().state = InteractionState.Failed;
super.tick0(var1, var2, var3, var4, var5);
} else {
ModelAsset var27 = ModelAsset.getAssetMap().getAsset(var26.getModelReference().getModelAssetId());
CapturedNPCMetadata var28 = var11.getFromMetadataOrDefault("CapturedEntity", CapturedNPCMetadata.CODEC);
if (var27 != null) {
var28.setIconPath(var27.getIcon());
}
String var29 = NPCPlugin.get().getName(var14.getRoleIndex());
if (var29 != null) {
var28.setNpcNameKey(var29);
}
Role var22 = var14.getRole();
if (var22 != null) {
String var23 = var22.getAppearanceName();
ModelAsset var24 = ModelAsset.getAssetMap().getAsset(var23);
if (var24 == null) {
var28.setFullItemIcon(this.fullIcon);
} else {
String var25 = var24.getIcon();
if (var25 != null) {
var28.setFullItemIcon(var25);
} else {
var28.setFullItemIcon(this.fullIcon);
}
}
var28.setAlarmStore(var6.getComponent(var13, AlarmStore.getComponentType()));
ItemStack var30 = var11.withMetadata(CapturedNPCMetadata.KEYED_CODEC, var28);
var9.getInventory().replaceItemStackInSlot(var10, var7, var30);
var6.removeEntity(var13, RemoveReason.REMOVE);
}
}
}
}
}
}
}
}
}
}
}
@Override
class="kw">protected void interactWithBlock(
@Nonnull World var1,
@Nonnull CommandBuffer<EntityStore> var2,
@Nonnull InteractionType var3,
@Nonnull InteractionContext var4,
@Nullable ItemStack var5,
@Nonnull Vector3i var6,
@Nonnull CooldownHandler var7
) {
ItemStack var8 = var4.getHeldItem();
if (var8 == null) {
var4.getState().state = InteractionState.Failed;
} else {
Ref var9 = var4.getEntity();
InventoryComponent.Hotbar var10 = var2.getComponent(var9, InventoryComponent.Hotbar.getComponentType());
if (var10 == null) {
var4.getState().state = InteractionState.Failed;
} else {
byte var11 = var10.getActiveSlot();
CapturedNPCMetadata var12 = var8.getFromMetadataOrNull("CapturedEntity", CapturedNPCMetadata.CODEC);
if (var12 == null) {
var4.getState().state = InteractionState.Failed;
} else {
BlockPosition var13 = var4.getTargetBlock();
if (var13 == null) {
var4.getState().state = InteractionState.Failed;
} else {
Store var14 = var1.getChunkStore().getStore();
Ref var15 = var1.getChunkStore().getChunkSectionReferenceAtBlock(var13.x, var13.y, var13.z);
if (var15 != null && var15.isValid()) {
BlockSection var16 = var14.getComponent(var15, BlockSection.getComponentType());
BlockComponentSection var17 = var14.getComponent(var15, BlockComponentSection.getComponentType());
if (var16 != null && var17 != null) {
int var18 = ChunkUtil.indexBlock(var13.x, var13.y, var13.z);
Ref var19 = var17.getBlockReference(var18);
if (var19 == null || !var19.isValid()) {
BlockType var20 = BlockType.getAssetMap().getAsset(var16.get(var18));
if (var20 != null && BlockEntity.declaresComponent(var20, CoopBlock.getComponentType())) {
var19 = BlockEntity.ensureBlockEntity(var14, var15, var17, var13.x, var13.y, var13.z, var20, var16.getFiller(var18));
}
}
ItemStack var25 = var8.withMetadata(null);
if (var19 != null && var19.isValid()) {
CoopBlock var21 = var14.getComponent(var19, CoopBlock.getComponentType());
if (var21 != null) {
WorldTimeResource var28 = var2.getResource(WorldTimeResource.getResourceType());
if (var21.tryPutResident(var12, var28)) {
var1.execute(
() -> var21.ensureSpawnResidentsInWorld(
var1,
var1.getEntityStore().getStore(),
new Vector3d(var13.x, var13.y, var13.z),
new Vector3d().set(Vector3dUtil.FORWARD)
)
);
var10.getInventory().replaceItemStackInSlot(var11, var8, var25);
var4.getState().state = InteractionState.Finished;
} else {
var4.getState().state = InteractionState.Failed;
}
class="kw">return;
}
}
Vector3d var26 = new Vector3d(var13.x + 0.5F, var13.y, var13.z + 0.5F);
if (var4.getClientState() != null) {
BlockFace var22 = BlockFace.fromProtocolFace(var4.getClientState().blockFace);
if (var22 != null) {
Vector3ic var23 = var22.getDirection();
var26.add(var23.x(), var23.y(), var23.z());
}
}
String var27 = var12.getNpcNameKey();
int var29 = NPCPlugin.get().getIndex(var27);
AlarmStore var24 = var12.getAlarmStore();
var2.run(var3x -> NPCPlugin.get().spawnEntity(var3x, var29, var26, Rotation3f.IDENTITY, null, (var1x, var2x, var3xx) -> {
if (var24 != null) {
var2x.putComponent(AlarmStore.getComponentType(), var24);
}
}, null));
var10.getInventory().replaceItemStackInSlot(var11, var8, var25);
} else {
var4.getState().state = InteractionState.Failed;
}
} else {
var4.getState().state = InteractionState.Failed;
}
}
}
}
}
}
@Override
class="kw">protected void simulateInteractWithBlock(
@Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nullable ItemStack var3, @Nonnull World var4, @Nonnull Vector3i var5
) {
}
}