EnterPortalInteraction class
Пакет: com.hypixel.hytale.builtin.portals.interactions
Файл: com/hypixel/hytale/builtin/portals/interactions/EnterPortalInteraction.java
extends: SimpleBlockInteraction
Поля (24)
| Модификаторы | Тип | Имя |
|---|---|---|
|
OKAY,
WORLD_DEAD,
DIED_IN_WORLD, |
NO_SPAWN_AVAILABLE |
|
|
break |
|
|
break |
|
|
break |
|
|
return |
|
Ref |
var10 |
|
ChunkStore |
var11 |
|
Ref |
var11 |
|
Store |
var12 |
|
PortalDeviceActivePage |
var12 |
|
PortalDevice |
var13 |
|
Ref |
var14 |
|
BlockSection |
var15 |
|
BlockType |
var16 |
|
RotationTuple |
var17 |
|
double |
var18 |
|
PortalWorld |
var2 |
|
Transform |
var20 |
|
PlayerRef |
var21 |
|
World |
var22 |
|
UUIDComponent |
var23 |
|
UUID |
var24 |
|
Ref |
var8 |
|
Player |
var9 |
Методы (9)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
TargetWorldState TargetWorldState() |
|
|
if if(var9 == null) |
|
|
if if(var13 == null) |
|
|
if if(var15 == null) |
|
|
if if(var16 == null) |
|
|
if if(var21 == null) |
|
|
if if(var22 == null) |
|
|
if if(var23 == null) |
|
|
switch switch(var10x) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.portals.interactions;
class="kw">import com.hypixel.hytale.builtin.instances.InstancesPlugin;
class="kw">import com.hypixel.hytale.builtin.portals.components.PortalDevice;
class="kw">import com.hypixel.hytale.builtin.portals.events.EnterPortalEvent;
class="kw">import com.hypixel.hytale.builtin.portals.resources.PortalWorld;
class="kw">import com.hypixel.hytale.builtin.portals.ui.PortalDeviceActivePage;
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.Store;
class="kw">import com.hypixel.hytale.math.vector.Transform;
class="kw">import com.hypixel.hytale.protocol.InteractionState;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.protocol.WaitForDataFrom;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.RotationTuple;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.modules.block.BlockModule;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.client.SimpleBlockInteraction;
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.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 java.time.Duration;
class="kw">import java.util.UUID;
class="kw">import java.util.concurrent.CompletableFuture;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3i;
class="kw">public class EnterPortalInteraction class="kw">extends SimpleBlockInteraction {
@Nonnull
class="kw">private class="kw">static class="kw">final Message MESSAGE_PORTALS_DEVICE_REF_INVALID = Message.translation("server.portals.device.refInvalid");
@Nonnull
class="kw">private class="kw">static class="kw">final Message MESSAGE_PORTALS_DEVICE_WORLD_IS_DEAD = Message.translation("server.portals.device.worldIsDead");
@Nonnull
class="kw">private class="kw">static class="kw">final Message MESSAGE_PORTALS_DEVICE_NO_SPAWN = Message.translation("server.portals.device.worldNoSpawn");
@Nonnull
class="kw">private class="kw">static class="kw">final Message MESSAGE_PORTALS_DEVICE_BLOCK_ENTITY_REF_INVALID = Message.translation("server.portals.device.blockEntityRefInvalid");
@Nonnull
class="kw">public class="kw">static class="kw">final Duration MINIMUM_TIME_IN_WORLD = Duration.ofSeconds(3L);
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<EnterPortalInteraction> CODEC = BuilderCodec.builder(
EnterPortalInteraction.class, EnterPortalInteraction::new, SimpleBlockInteraction.CODEC
)
.build();
class="kw">public EnterPortalInteraction() {
}
@Nonnull
@Override
class="kw">public WaitForDataFrom getWaitForDataFrom() {
class="kw">return WaitForDataFrom.Server;
}
@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
) {
Ref var8 = var4.getEntity();
Player var9 = var2.getComponent(var8, Player.getComponentType());
if (var9 == null) {
var4.getState().state = InteractionState.Failed;
} else if (var9.getSinceLastSpawnNanos() < MINIMUM_TIME_IN_WORLD.toNanos()) {
var4.getState().state = InteractionState.Failed;
} else {
Ref var10 = BlockModule.getBlockEntity(var1, var6.x, var6.y, var6.z);
if (var10 != null && var10.isValid()) {
ChunkStore var11 = var1.getChunkStore();
Store var12 = var11.getStore();
PortalDevice var13 = var12.getComponent(var10, PortalDevice.getComponentType());
if (var13 == null) {
var4.getState().state = InteractionState.Failed;
} else {
Ref var14 = var11.getChunkSectionReferenceAtBlock(var6.x, var6.y, var6.z);
if (var14 != null && var14.isValid()) {
BlockSection var15 = var12.getComponent(var14, BlockSection.getComponentType());
if (var15 == null) {
var4.getState().state = InteractionState.Failed;
} else {
BlockType var16 = BlockType.getAssetMap().getAsset(var15.get(var6.x, var6.y, var6.z));
if (var16 == null) {
var4.getState().state = InteractionState.Failed;
} else {
RotationTuple var17 = var15.getRotation(var6.x, var6.y, var6.z);
double var18 = var17.yaw().getRadians() + Math.PI;
Transform var20 = new Transform(var6.x + 0.5, var6.y + 0.5, var6.z + 0.5, 0.0F, (float)var18, 0.0F);
PlayerRef var21 = var2.getComponent(var8, PlayerRef.getComponentType());
if (var21 == null) {
var4.getState().state = InteractionState.Failed;
} else {
World var22 = var13.getDestinationWorld();
if (var22 == null) {
var21.sendMessage(MESSAGE_PORTALS_DEVICE_WORLD_IS_DEAD);
var4.getState().state = InteractionState.Failed;
} else {
UUIDComponent var23 = var2.getComponent(var8, UUIDComponent.getComponentType());
if (var23 == null) {
var4.getState().state = InteractionState.Failed;
} else {
UUID var24 = var23.getUuid();
var12.invoke(var10, new EnterPortalEvent(var4, var6, var10, var13));
fetchTargetWorldState(var22, var24).thenAcceptAsync(var10x -> {
if (!var8.isValid()) {
var21.sendMessage(MESSAGE_PORTALS_DEVICE_REF_INVALID);
var4.getState().state = InteractionState.Failed;
} else {
class="kw">switch (var10x) {
case OKAY:
InstancesPlugin.teleportPlayerToInstance(var8, var2, var22, var20);
break;
case WORLD_DEAD:
var21.sendMessage(MESSAGE_PORTALS_DEVICE_WORLD_IS_DEAD);
var4.getState().state = InteractionState.Failed;
break;
case DIED_IN_WORLD:
Ref var11 = BlockModule.getBlockEntity(var1, var6.x, var6.y, var6.z);
if (var11 == null || !var11.isValid()) {
var21.sendMessage(MESSAGE_PORTALS_DEVICE_BLOCK_ENTITY_REF_INVALID);
var4.getState().state = InteractionState.Failed;
class="kw">return;
}
PortalDeviceActivePage var12 = new PortalDeviceActivePage(var21, var13.getConfig(), var11);
var9.getPageManager().openCustomPage(var8, var1.getEntityStore().getStore(), var12);
break;
case NO_SPAWN_AVAILABLE:
var21.sendMessage(MESSAGE_PORTALS_DEVICE_NO_SPAWN);
var4.getState().state = InteractionState.Failed;
}
}
}, var1);
}
}
}
}
}
} else {
var4.getState().state = InteractionState.Failed;
}
}
} else {
var4.getState().state = InteractionState.Failed;
}
}
}
@Nonnull
class="kw">private class="kw">static CompletableFuture<EnterPortalInteraction.TargetWorldState> fetchTargetWorldState(@Nonnull World var0, @Nonnull UUID var1) {
class="kw">return CompletableFuture.supplyAsync(() -> {
PortalWorld var2 = var0.getEntityStore().getStore().getResource(PortalWorld.getResourceType());
if (!var2.exists()) {
class="kw">return EnterPortalInteraction.TargetWorldState.WORLD_DEAD;
} else if (var2.getSpawnPoint() == null) {
class="kw">return EnterPortalInteraction.TargetWorldState.NO_SPAWN_AVAILABLE;
} else {
class="kw">return var2.getDiedInWorld().contains(var1) ? EnterPortalInteraction.TargetWorldState.DIED_IN_WORLD : EnterPortalInteraction.TargetWorldState.OKAY;
}
}, var0);
}
@Override
class="kw">protected void simulateInteractWithBlock(
@Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nullable ItemStack var3, @Nonnull World var4, @Nonnull Vector3i var5
) {
}
class="kw">private enum TargetWorldState {
OKAY,
WORLD_DEAD,
DIED_IN_WORLD,
NO_SPAWN_AVAILABLE;
TargetWorldState() {
}
}
}