CameraDemo class
Пакет: com.hypixel.hytale.server.core.command.commands.player.camera
Файл: com/hypixel/hytale/server/core/command/commands/player/camera/CameraDemo.java
Поля (19)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
CameraDemo |
INSTANCE |
|
ServerCameraSettings |
var0 |
|
CameraManager |
var1 |
|
int |
var10 |
|
int |
var11 |
|
int |
var12 |
|
String |
var13 |
|
int |
var14 |
|
int |
var15 |
|
int |
var16 |
|
int |
var17 |
|
Ref |
var2 |
|
Store |
var3 |
|
World |
var4 |
|
Vector3i |
var5 |
|
CameraManager |
var6 |
|
Vector3i |
var7 |
|
String |
var8 |
|
int |
var9 |
Методы (11)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Unknown key! " + var8) |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Unknown key! " + var13) |
public |
void |
activatevoid activate() |
public |
void |
deactivatevoid deactivate() |
|
|
if if(!this.isActive) |
|
|
if if(this.isActive) |
|
|
if if(var1 != null) |
|
|
if if(var9 == Integer.MIN_VALUE) |
|
|
if if(var15 == Integer.MIN_VALUE) |
private |
void |
onAddNewPlayervoid onAddNewPlayer(@Nonnull PlayerRef var1) |
private |
void |
onPlayerMouseButtonvoid onPlayerMouseButton(@Nonnull PlayerMouseButtonEvent var1) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.command.commands.player.camera;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.event.EventRegistry;
class="kw">import com.hypixel.hytale.math.iterator.BlockIterator;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.protocol.ClientCameraView;
class="kw">import com.hypixel.hytale.protocol.Direction;
class="kw">import com.hypixel.hytale.protocol.MouseButtonState;
class="kw">import com.hypixel.hytale.protocol.MouseButtonType;
class="kw">import com.hypixel.hytale.protocol.MouseInputType;
class="kw">import com.hypixel.hytale.protocol.MovementForceRotationType;
class="kw">import com.hypixel.hytale.protocol.PositionDistanceOffsetType;
class="kw">import com.hypixel.hytale.protocol.RotationType;
class="kw">import com.hypixel.hytale.protocol.ServerCameraSettings;
class="kw">import com.hypixel.hytale.protocol.packets.camera.SetServerCamera;
class="kw">import com.hypixel.hytale.server.core.HytaleServer;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.CameraManager;
class="kw">import com.hypixel.hytale.server.core.event.events.player.PlayerConnectEvent;
class="kw">import com.hypixel.hytale.server.core.event.events.player.PlayerInteractEvent;
class="kw">import com.hypixel.hytale.server.core.event.events.player.PlayerMouseButtonEvent;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.Universe;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.concurrent.CopyOnWriteArrayList;
class="kw">import javax.annotation.Nonnull;
class="kw">import org.joml.Vector3f;
class="kw">import org.joml.Vector3i;
class="kw">public class CameraDemo {
class="kw">public class="kw">static class="kw">final CameraDemo INSTANCE = new CameraDemo();
class="kw">private class="kw">final EventRegistry eventRegistry = new EventRegistry(
new CopyOnWriteArrayList<>(), () -> this.isActive, "CameraDemo is not active!", HytaleServer.get().getEventBus()
);
class="kw">private class="kw">final ServerCameraSettings cameraSettings = createServerCameraSettings();
class="kw">private boolean isActive;
class="kw">public CameraDemo() {
}
class="kw">public void activate() {
if (!this.isActive) {
this.eventRegistry.enable();
this.isActive = true;
this.eventRegistry.register(PlayerConnectEvent.class, var1 -> this.onAddNewPlayer(var1.getPlayerRef()));
this.eventRegistry.register(PlayerMouseButtonEvent.class, this::onPlayerMouseButton);
this.eventRegistry.registerGlobal(PlayerInteractEvent.class, var0 -> var0.setCancelled(true));
Universe.get().getPlayers().forEach(this::onAddNewPlayer);
}
}
class="kw">public void deactivate() {
if (this.isActive) {
this.eventRegistry.shutdownAndCleanup(false);
Universe.get().getPlayers().forEach(var0 -> {
CameraManager var1 = var0.getComponent(CameraManager.getComponentType());
if (var1 != null) {
var1.resetCamera(var0);
}
});
this.isActive = false;
}
}
class="kw">private void onAddNewPlayer(@Nonnull PlayerRef var1) {
var1.getPacketHandler().writeNoCache(new SetServerCamera(ClientCameraView.Custom, true, this.cameraSettings));
}
class="kw">private void onPlayerMouseButton(@Nonnull PlayerMouseButtonEvent var1) {
if (var1.getMouseButton().state == MouseButtonState.Released) {
Ref var2 = var1.getPlayerRef();
if (var2.isValid()) {
Store var3 = var2.getStore();
World var4 = var3.getExternalData().getWorld();
Vector3i var5 = var1.getTargetBlock();
CameraManager var6 = var3.getComponent(var2, CameraManager.getComponentType());
assert var6 != null;
Vector3i var7 = var6.getLastMouseButtonPressedPosition(var1.getMouseButton().mouseButtonType);
if (var1.getMouseButton().mouseButtonType == MouseButtonType.Middle) {
if (var1.getItemInHand() != null && var1.getItemInHand().hasBlockType() && var5 != null) {
String var8 = var1.getItemInHand().getId();
int var9 = BlockType.getAssetMap().getIndex(var8);
if (var9 == Integer.MIN_VALUE) {
throw new IllegalArgumentException("Unknown key! " + var8);
}
if (!var7.equals(var5)) {
BlockIterator.iterateFromTo(var7, var5, (var2x, var3x, var4x, var5x, var7x, var9x, var11x, var13x, var15x) -> {
var4.getChunk(ChunkUtil.indexChunkFromBlock(var2x, var4x)).setBlock(var2x, var3x, var4x, var9);
class="kw">return true;
});
} else {
int var10 = var5.x();
int var11 = var5.z();
var4.getChunk(ChunkUtil.indexChunkFromBlock(var10, var11)).setBlock(var10, var5.y(), var11, var9);
}
}
} else if (var1.getMouseButton().mouseButtonType == MouseButtonType.Right) {
if (!var7.equals(var5)) {
BlockIterator.iterateFromTo(var7, var5, (var1x, var2x, var3x, var4x, var6x, var8x, var10x, var12x, var14x) -> {
var4.getChunk(ChunkUtil.indexChunkFromBlock(var1x, var3x)).setBlock(var1x, var2x, var3x, 0);
class="kw">return true;
});
} else {
int var12 = var5.x();
int var14 = var5.z();
var4.getChunk(ChunkUtil.indexChunkFromBlock(var12, var14)).setBlock(var12, var5.y(), var14, 0);
}
} else if (var1.getMouseButton().mouseButtonType == MouseButtonType.Left
&& var1.getItemInHand() != null
&& var1.getItemInHand().hasBlockType()
&& var5 != null) {
String var13 = var1.getItemInHand().getId();
int var15 = BlockType.getAssetMap().getIndex(var13);
if (var15 == Integer.MIN_VALUE) {
throw new IllegalArgumentException("Unknown key! " + var13);
}
if (!var7.equals(var5)) {
BlockIterator.iterateFromTo(
var7.x(),
var7.y() + 1,
var7.z(),
var5.x(),
var5.y() + 1,
var5.z(),
(var2x, var3x, var4x, var5x, var7x, var9x, var11x, var13x, var15x) -> {
var4.getChunk(ChunkUtil.indexChunkFromBlock(var2x, var4x)).setBlock(var2x, var3x, var4x, var15);
class="kw">return true;
}
);
} else {
int var16 = var5.x();
int var17 = var5.z();
var4.getChunk(ChunkUtil.indexChunkFromBlock(var16, var17)).setBlock(var16, var5.y() + 1, var17, var15);
}
}
}
}
}
@Nonnull
class="kw">private class="kw">static ServerCameraSettings createServerCameraSettings() {
ServerCameraSettings var0 = new ServerCameraSettings();
var0.positionLerpSpeed = 0.2F;
var0.rotationLerpSpeed = 0.2F;
var0.distance = 20.0F;
var0.displayCursor = true;
var0.sendMouseMotion = true;
var0.isFirstPerson = false;
var0.movementForceRotationType = MovementForceRotationType.Custom;
var0.eyeOffset = true;
var0.positionDistanceOffsetType = PositionDistanceOffsetType.DistanceOffset;
var0.rotationType = RotationType.Custom;
var0.rotation = new Direction(0.0F, (float) (-Math.PI / 2), 0.0F);
var0.mouseInputType = MouseInputType.LookAtPlane;
var0.planeNormal = new Vector3f(0.0F, 1.0F, 0.0F);
class="kw">return var0;
}
}