ParticleSpawnPage class
Пакет: com.hypixel.hytale.server.core.asset.type.particle.pages
Файл: com/hypixel/hytale/server/core/asset/type/particle/pages/ParticleSpawnPage.java
extends: InteractiveCustomUIPage<ParticleSpawnPage.ParticleSpawnPageEventData>
Поля (45)
| Модификаторы | Тип | Имя |
|---|---|---|
|
public static final BuilderCodec<ParticleSpawnPage.ParticleSpawnPageEventData> |
CODEC |
final |
String |
COMMON_TEXT_BUTTON_DOCUMENT |
|
static final String |
KEY_ACTION |
|
static final String |
KEY_PARTICLE_SYSTEM_ID |
|
static final String |
KEY_ROTATION_OFFSET |
|
static final String |
KEY_SEARCH_QUERY |
|
private String |
action |
|
|
break |
|
|
break |
|
private String |
particleSystemId |
|
private float |
rotationOffset |
|
private String |
searchQuery |
|
TransformComponent |
var10 |
|
int |
var10 |
|
UICommandBuilder |
var11 |
|
HeadRotation |
var12 |
|
String |
var12 |
|
String |
var13 |
|
Rangef |
var13 |
|
Vector3d |
var14 |
|
Vector3d |
var15 |
|
Rotation3f |
var16 |
|
Holder |
var17 |
|
TransformComponent |
var18 |
|
HeadRotation |
var19 |
|
Vector3d |
var20 |
|
Rotation3f |
var21 |
|
Vector3d |
var22 |
|
|
var22 |
|
|
var22 |
|
UICommandBuilder |
var4 |
|
UIEventBuilder |
var5 |
|
Set |
var5 |
|
ParticleSystem |
var5 |
|
SpatialResource |
var6 |
|
Object2IntMap |
var6 |
|
float |
var6 |
|
List |
var7 |
|
float |
var7 |
|
|
var7 |
|
|
var7 |
|
float |
var8 |
|
|
var8 |
|
|
var8 |
|
int |
var9 |
Методы (16)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
public |
ParticleSpawnPageEventDatapublic ParticleSpawnPageEventData() |
private |
void |
buildParticleListvoid buildParticleList(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) |
|
|
for for(String var8 : var5) |
abstract |
|
for for(int var11 = this.particleSystemIds.size() |
public |
void |
handleDataEventvoid handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull ParticleSpawnPage.ParticleSpawnPageEventData var3) |
|
|
if if(var3.searchQuery != null) |
|
|
if if(var3.particleSystemId != null) |
|
|
if if(var12 != null) |
|
|
if if(this.selectedParticleSystemId != null) |
|
|
if if(var9 > 0) |
|
|
if if(var13 != null) |
|
|
if if(var22 == null) |
|
|
if if(var14 != null) |
private |
void |
selectParticleSystemvoid selectParticleSystem(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull String var3, @Nonnull UICommandBuilder var4) |
abstract |
|
super super(var1, CustomPageLifetime.CanDismiss, ParticleSpawnPage.ParticleSpawnPageEventData.CODEC) |
|
|
switch switch(var3.action) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.asset.type.particle.pages;
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.common.util.StringCompareUtil;
class="kw">import com.hypixel.hytale.component.AddReason;
class="kw">import com.hypixel.hytale.component.Holder;
class="kw">import com.hypixel.hytale.component.NonSerialized;
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.component.spatial.SpatialResource;
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.Rangef;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.CustomPageLifetime;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType;
class="kw">import com.hypixel.hytale.server.core.asset.type.particle.config.ParticleSpawnerGroup;
class="kw">import com.hypixel.hytale.server.core.asset.type.particle.config.ParticleSystem;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage;
class="kw">import com.hypixel.hytale.server.core.modules.entity.EntityModule;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId;
class="kw">import com.hypixel.hytale.server.core.ui.Value;
class="kw">import com.hypixel.hytale.server.core.ui.builder.EventData;
class="kw">import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder;
class="kw">import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.ParticleUtil;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.core.util.TargetUtil;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
class="kw">import java.util.Comparator;
class="kw">import java.util.List;
class="kw">import java.util.Locale;
class="kw">import java.util.Set;
class="kw">import java.util.stream.Collectors;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">public class ParticleSpawnPage class="kw">extends InteractiveCustomUIPage<ParticleSpawnPage.ParticleSpawnPageEventData> {
class="kw">private class="kw">static class="kw">final String COMMON_TEXT_BUTTON_DOCUMENT = "Common/TextButton.ui";
class="kw">private class="kw">static class="kw">final Value<String> BUTTON_LABEL_STYLE = Value.ref("Common/TextButton.ui", "LabelStyle");
class="kw">private class="kw">static class="kw">final Value<String> BUTTON_LABEL_STYLE_SELECTED = Value.ref("Common/TextButton.ui", "SelectedLabelStyle");
@Nonnull
class="kw">private String searchQuery = "";
class="kw">private List<String> particleSystemIds;
@Nullable
class="kw">private String selectedParticleSystemId;
@Nullable
class="kw">private Ref<EntityStore> particleSystemPreview;
class="kw">private Vector3d position;
class="kw">private Rotation3f rotation;
class="kw">public ParticleSpawnPage(@Nonnull PlayerRef var1) {
super(var1, CustomPageLifetime.CanDismiss, ParticleSpawnPage.ParticleSpawnPageEventData.CODEC);
}
@Override
class="kw">public void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) {
var2.append("Pages/ParticleSpawnPage.ui");
var3.addEventBinding(CustomUIEventBindingType.ValueChanged, "#SearchInput", EventData.of("@SearchQuery", "#SearchInput.Value"), false);
var3.addEventBinding(
CustomUIEventBindingType.ValueChanged,
"#RotationOffset",
new EventData().append("Action", "UpdateRotationOffset").append("@RotationOffset", "#RotationOffset.Value"),
false
);
var3.addEventBinding(CustomUIEventBindingType.Activating, "#Spawn", new EventData().append("Action", "Spawn"), false);
this.buildParticleList(var1, var2, var3, var4);
}
class="kw">public void handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull ParticleSpawnPage.ParticleSpawnPageEventData var3) {
if (var3.searchQuery != null) {
this.searchQuery = var3.searchQuery.trim().toLowerCase(Locale.ROOT);
UICommandBuilder var4 = new UICommandBuilder();
UIEventBuilder var5 = new UIEventBuilder();
this.buildParticleList(var1, var4, var5, var2);
this.sendUpdate(var4, var5, false);
} else {
class="kw">switch (var3.action) {
case "Select":
if (var3.particleSystemId != null) {
UICommandBuilder var11 = new UICommandBuilder();
this.selectParticleSystem(var1, var2, var3.particleSystemId, var11);
this.sendUpdate(var11, null, false);
}
break;
case "UpdateRotationOffset":
if (this.particleSystemPreview.isValid()) {
TransformComponent var10 = var2.getComponent(this.particleSystemPreview, TransformComponent.getComponentType());
var10.getRotation().setYaw(this.rotation.yaw() + (float)Math.toRadians(var3.rotationOffset));
HeadRotation var12 = var2.getComponent(this.particleSystemPreview, HeadRotation.getComponentType());
if (var12 != null) {
var12.getRotation().setYaw(this.rotation.yaw() + (float)Math.toRadians(var3.rotationOffset));
}
}
break;
case "Spawn":
if (this.selectedParticleSystemId != null) {
if (this.particleSystemPreview.isValid()) {
var2.removeEntity(this.particleSystemPreview, RemoveReason.REMOVE);
}
SpatialResource var6 = var2.getResource(EntityModule.get().getPlayerSpatialResourceType());
List var7 = SpatialResource.getThreadLocalReferenceList();
var6.getSpatialStructure().collect(this.position, 75.0, var7);
ParticleUtil.spawnParticleEffect(this.selectedParticleSystemId, this.position, this.rotation, var7, var2);
}
}
}
}
@Override
class="kw">public void onDismiss(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2) {
if (this.particleSystemPreview.isValid()) {
var2.removeEntity(this.particleSystemPreview, RemoveReason.REMOVE);
}
}
class="kw">private void buildParticleList(
@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4
) {
var2.clear("#ParticleSystemList");
Set var5 = ParticleSystem.getAssetMap().getAssetMap().keySet();
if (!this.searchQuery.isEmpty()) {
Object2IntMap var6 = new Object2IntOpenHashMap(var5.size());
for (String var8 : var5) {
int var9 = StringCompareUtil.getFuzzyDistance(var8, this.searchQuery, Locale.ENGLISH);
if (var9 > 0) {
var6.put(var8, var9);
}
}
this.particleSystemIds = var6.keySet()
.stream()
.sorted()
.sorted(Comparator.comparingInt(var6::getInt).reversed())
.limit(20L)
.collect(Collectors.toList());
} else {
this.particleSystemIds = var5.stream().sorted(String::compareTo).collect(Collectors.toList());
}
int var10 = 0;
for (int var11 = this.particleSystemIds.size(); var10 < var11; var10++) {
String var12 = this.particleSystemIds.get(var10);
String var13 = "#ParticleSystemList[" + var10 + "]";
var2.append("#ParticleSystemList", "Common/TextButton.ui");
var2.set(var13 + " #Button.Text", var12);
var3.addEventBinding(
CustomUIEventBindingType.Activating, var13 + " #Button", new EventData().append("Action", "Select").append("ParticleSystemId", var12), false
);
}
if (!this.particleSystemIds.isEmpty()) {
if (!this.particleSystemIds.contains(this.selectedParticleSystemId)) {
this.selectParticleSystem(var1, var4, this.particleSystemIds.getFirst(), var2);
} else if (this.selectedParticleSystemId != null) {
this.selectParticleSystem(var1, var4, this.selectedParticleSystemId, var2);
}
}
}
class="kw">private void selectParticleSystem(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull String var3, @Nonnull UICommandBuilder var4) {
if (this.selectedParticleSystemId != null && this.particleSystemIds.contains(this.selectedParticleSystemId)) {
var4.set("#ParticleSystemList[" + this.particleSystemIds.indexOf(this.selectedParticleSystemId) + "] #Button.Style", BUTTON_LABEL_STYLE);
}
var4.set("#ParticleSystemList[" + this.particleSystemIds.indexOf(var3) + "] #Button.Style", BUTTON_LABEL_STYLE_SELECTED);
var4.set("#ParticleSystemName.Text", var3);
ParticleSystem var5 = ParticleSystem.getAssetMap().getAsset(var3);
float var6 = var5.getLifeSpan();
var4.set("#SystemLifespan.Text", var6 <= 0.0F ? "Infinite" : String.valueOf(var6));
float var7 = Float.MAX_VALUE;
float var8 = -1.0F;
for (ParticleSpawnerGroup var12 : var5.getSpawners()) {
Rangef var13 = var12.getLifeSpan();
if (var13 != null) {
var7 = Math.min(var7, var13.min);
var8 = Math.max(var8, var13.max);
} else {
var7 = -1.0F;
var8 = Float.MAX_VALUE;
}
}
var4.set(
"#ParticleGroupLifespan.Text",
String.format(
"%s - %s", var7 < 0.0F ? "Unset" : String.valueOf(var7), var8 >= Float.MAX_VALUE ? "Infinite" : (var8 < 0.0F ? "Unset" : String.valueOf(var8))
)
);
this.selectedParticleSystemId = var3;
if (this.particleSystemPreview != null && this.particleSystemPreview.isValid()) {
if (this.particleSystemPreview != null && this.particleSystemPreview.isValid()) {
}
} else {
TransformComponent var18 = var2.getComponent(var1, TransformComponent.getComponentType());
assert var18 != null;
HeadRotation var19 = var2.getComponent(var1, HeadRotation.getComponentType());
assert var19 != null;
Vector3d var20 = var18.getPosition();
Rotation3f var21 = var19.getRotation();
Vector3d var22 = TargetUtil.getTargetLocation(var1, 8.0, var2);
if (var22 == null) {
var22 = new Vector3d(var20).add(Transform.getDirection(var21.pitch(), var21.yaw()).mul(4.0));
}
Vector3d var14 = TargetUtil.getTargetLocation(var2.getExternalData().getWorld(), var0 -> var0 != 0, var22.x, var22.y, var22.z, 0.0, -1.0, 0.0, 8.0);
if (var14 != null) {
var22 = var14;
}
var22.add(0.0, var5.getBoundingRadius(), 0.0);
Vector3d var15 = new Vector3d(var20).sub(var22);
var15.y = 0.0;
Rotation3f var16 = Rotation3f.lookAt(var15);
this.position = var22;
this.rotation = var16;
Holder var17 = var2.getRegistry().newHolder();
var17.addComponent(EntityStore.REGISTRY.getNonSerializedComponentType(), NonSerialized.get());
var17.addComponent(NetworkId.getComponentType(), new NetworkId(var2.getExternalData().takeNextNetworkId()));
var17.addComponent(TransformComponent.getComponentType(), new TransformComponent(var22, var16));
this.particleSystemPreview = var2.addEntity(var17, AddReason.SPAWN);
}
}
class="kw">public class="kw">static class ParticleSpawnPageEventData {
class="kw">static class="kw">final String KEY_ACTION = "Action";
class="kw">static class="kw">final String KEY_PARTICLE_SYSTEM_ID = "ParticleSystemId";
class="kw">static class="kw">final String KEY_SEARCH_QUERY = "@SearchQuery";
class="kw">static class="kw">final String KEY_ROTATION_OFFSET = "@RotationOffset";
class="kw">public class="kw">static class="kw">final BuilderCodec<ParticleSpawnPage.ParticleSpawnPageEventData> CODEC = BuilderCodec.builder(
ParticleSpawnPage.ParticleSpawnPageEventData.class, ParticleSpawnPage.ParticleSpawnPageEventData::new
)
.append(new KeyedCodec<>("Action", Codec.STRING), (var0, var1) -> var0.action = var1, var0 -> var0.action)
.add()
.append(new KeyedCodec<>("ParticleSystemId", Codec.STRING), (var0, var1) -> var0.particleSystemId = var1, var0 -> var0.particleSystemId)
.add()
.append(new KeyedCodec<>("@SearchQuery", Codec.STRING), (var0, var1) -> var0.searchQuery = var1, var0 -> var0.searchQuery)
.add()
.append(new KeyedCodec<>("@RotationOffset", Codec.FLOAT), (var0, var1) -> var0.rotationOffset = var1, var0 -> var0.rotationOffset)
.add()
.build();
class="kw">private String particleSystemId;
class="kw">private String action;
class="kw">private String searchQuery;
class="kw">private float rotationOffset;
class="kw">public ParticleSpawnPageEventData() {
}
}
}