mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
commit
acddfeeb51
376 changed files with 4910 additions and 5710 deletions
14
.github/workflows/maven.yml
vendored
14
.github/workflows/maven.yml
vendored
|
@ -8,10 +8,10 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Build with Maven
|
||||
run: mvn package --file pom.xml
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Build with Maven
|
||||
run: mvn package --file pom.xml
|
||||
|
|
52
Jenkinsfile
vendored
Normal file
52
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
maven 'Maven 3'
|
||||
jdk 'Java 8'
|
||||
}
|
||||
options {
|
||||
buildDiscarder(logRotator(artifactNumToKeepStr: '20'))
|
||||
}
|
||||
stages {
|
||||
stage ('Build') {
|
||||
steps {
|
||||
sh 'mvn clean package'
|
||||
}
|
||||
post {
|
||||
success {
|
||||
archiveArtifacts artifacts: 'target/*.jar', excludes: 'target/*-sources.jar', fingerprint: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Deploy') {
|
||||
when {
|
||||
branch "master"
|
||||
}
|
||||
|
||||
steps {
|
||||
rtMavenDeployer(
|
||||
id: "maven-deployer",
|
||||
serverId: "opencollab-artifactory",
|
||||
releaseRepo: "maven-releases",
|
||||
snapshotRepo: "maven-snapshots"
|
||||
)
|
||||
rtMavenResolver(
|
||||
id: "maven-resolver",
|
||||
serverId: "opencollab-artifactory",
|
||||
releaseRepo: "maven-deploy-release",
|
||||
snapshotRepo: "maven-deploy-snapshot"
|
||||
)
|
||||
rtMavenRun(
|
||||
pom: 'pom.xml',
|
||||
goals: 'javadoc:jar source:jar install -DskipTests',
|
||||
deployerId: "maven-deployer",
|
||||
resolverId: "maven-resolver"
|
||||
)
|
||||
rtPublishBuildInfo(
|
||||
serverId: "opencollab-artifactory"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
README.md
13
README.md
|
@ -1,14 +1,20 @@
|
|||
# MCProtocolLib
|
||||
MCProtocolLib is a simple library for communicating with a Minecraft client/server. It aims to allow people to make custom bots, clients, or servers for Minecraft easily.
|
||||
|
||||
MCProtocolLib is a simple library for communicating with a Minecraft client/server. It aims to allow people to make
|
||||
custom bots, clients, or servers for Minecraft easily.
|
||||
|
||||
## Example Code
|
||||
|
||||
See [example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java](https://github.com/Steveice10/MCProtocolLib/tree/master/example/com/github/steveice10/mc/protocol/test)
|
||||
|
||||
## Adding as a Dependency
|
||||
|
||||
The recommended way of fetching MCProtocolLib is through jitpack.io. See [here](https://jitpack.io/#Steveice10/MCProtocolLib) for more details on how to include MCProtocolLib in your project.
|
||||
The recommended way of fetching MCProtocolLib is through jitpack.io.
|
||||
See [here](https://jitpack.io/#Steveice10/MCProtocolLib) for more details on how to include MCProtocolLib in your
|
||||
project.
|
||||
|
||||
Maven:
|
||||
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
|
@ -25,6 +31,7 @@ Maven:
|
|||
```
|
||||
|
||||
Gradle:
|
||||
|
||||
```groovy
|
||||
allprojects {
|
||||
repositories {
|
||||
|
@ -38,6 +45,7 @@ dependencies {
|
|||
```
|
||||
|
||||
## Building the Source
|
||||
|
||||
MCProtocolLib uses Maven to manage dependencies. Simply run 'mvn clean install' in the source's directory.
|
||||
|
||||
## Support and development
|
||||
|
@ -45,5 +53,6 @@ MCProtocolLib uses Maven to manage dependencies. Simply run 'mvn clean install'
|
|||
Please join us at https://discord.gg/geysermc under #mcprotocollib for discussion and support for this project.
|
||||
|
||||
## License
|
||||
|
||||
MCProtocolLib is licensed under the **[MIT license](http://www.opensource.org/licenses/mit-license.html)**.
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ import com.github.steveice10.mc.auth.service.SessionService;
|
|||
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.ServerLoginHandler;
|
||||
import com.github.steveice10.mc.protocol.data.SubProtocol;
|
||||
import com.github.steveice10.mc.protocol.codec.MinecraftCodec;
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.status.PlayerInfo;
|
||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||
|
@ -16,9 +17,9 @@ import com.github.steveice10.mc.protocol.data.status.VersionInfo;
|
|||
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoBuilder;
|
||||
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler;
|
||||
import com.github.steveice10.mc.protocol.data.status.handler.ServerPingTimeHandler;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
|
||||
|
@ -35,8 +36,8 @@ import com.github.steveice10.packetlib.event.server.ServerClosedEvent;
|
|||
import com.github.steveice10.packetlib.event.server.SessionAddedEvent;
|
||||
import com.github.steveice10.packetlib.event.server.SessionRemovedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import com.github.steveice10.packetlib.tcp.TcpServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -58,16 +59,16 @@ public class MinecraftProtocolTest {
|
|||
private static final String PASSWORD = "Password";
|
||||
|
||||
public static void main(String[] args) {
|
||||
if(SPAWN_SERVER) {
|
||||
if (SPAWN_SERVER) {
|
||||
SessionService sessionService = new SessionService();
|
||||
sessionService.setProxy(AUTH_PROXY);
|
||||
|
||||
Server server = new TcpServer(HOST, PORT, MinecraftProtocol.class);
|
||||
Server server = new TcpServer(HOST, PORT, MinecraftProtocol::new);
|
||||
server.setGlobalFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
|
||||
server.setGlobalFlag(MinecraftConstants.VERIFY_USERS_KEY, VERIFY_USERS);
|
||||
server.setGlobalFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY, (ServerInfoBuilder) session ->
|
||||
new ServerStatusInfo(
|
||||
new VersionInfo(MinecraftConstants.GAME_VERSION, MinecraftConstants.PROTOCOL_VERSION),
|
||||
new VersionInfo(MinecraftCodec.CODEC.getMinecraftVersion(), MinecraftCodec.CODEC.getProtocolVersion()),
|
||||
new PlayerInfo(100, 0, new GameProfile[0]),
|
||||
Component.text("Hello world!"),
|
||||
null
|
||||
|
@ -75,19 +76,20 @@ public class MinecraftProtocolTest {
|
|||
);
|
||||
|
||||
server.setGlobalFlag(MinecraftConstants.SERVER_LOGIN_HANDLER_KEY, (ServerLoginHandler) session ->
|
||||
session.send(new ServerJoinGamePacket(
|
||||
session.send(new ClientboundLoginPacket(
|
||||
0,
|
||||
false,
|
||||
GameMode.SURVIVAL,
|
||||
GameMode.SURVIVAL,
|
||||
1,
|
||||
new String[] {"minecraft:world"},
|
||||
new String[]{"minecraft:world"},
|
||||
getDimensionTag(),
|
||||
getOverworldTag(),
|
||||
"minecraft:world",
|
||||
100,
|
||||
0,
|
||||
16,
|
||||
16,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
|
@ -106,21 +108,20 @@ public class MinecraftProtocolTest {
|
|||
public void sessionAdded(SessionAddedEvent event) {
|
||||
event.getSession().addListener(new SessionAdapter() {
|
||||
@Override
|
||||
public void packetReceived(PacketReceivedEvent event) {
|
||||
if(event.getPacket() instanceof ClientChatPacket) {
|
||||
ClientChatPacket packet = event.getPacket();
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
if (packet instanceof ServerboundChatPacket) {
|
||||
GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY);
|
||||
System.out.println(profile.getName() + ": " + packet.getMessage());
|
||||
System.out.println(profile.getName() + ": " + ((ServerboundChatPacket) packet).getMessage());
|
||||
|
||||
Component msg = Component.text("Hello, ")
|
||||
.color(NamedTextColor.GREEN)
|
||||
.append(Component.text(profile.getName())
|
||||
.color(NamedTextColor.AQUA)
|
||||
.decorate(TextDecoration.UNDERLINED))
|
||||
.color(NamedTextColor.AQUA)
|
||||
.decorate(TextDecoration.UNDERLINED))
|
||||
.append(Component.text("!")
|
||||
.color(NamedTextColor.GREEN));
|
||||
|
||||
event.getSession().send(new ServerChatPacket(msg));
|
||||
session.send(new ClientboundChatPacket(msg));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -129,7 +130,7 @@ public class MinecraftProtocolTest {
|
|||
@Override
|
||||
public void sessionRemoved(SessionRemovedEvent event) {
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol();
|
||||
if(protocol.getSubProtocol() == SubProtocol.GAME) {
|
||||
if (protocol.getState() == ProtocolState.GAME) {
|
||||
System.out.println("Closing server.");
|
||||
event.getServer().close(false);
|
||||
}
|
||||
|
@ -164,18 +165,18 @@ public class MinecraftProtocolTest {
|
|||
System.out.println("Server ping took " + pingTime + "ms"));
|
||||
|
||||
client.connect();
|
||||
while(client.isConnected()) {
|
||||
while (client.isConnected()) {
|
||||
try {
|
||||
Thread.sleep(5);
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void login() {
|
||||
MinecraftProtocol protocol = null;
|
||||
if(VERIFY_USERS) {
|
||||
MinecraftProtocol protocol;
|
||||
if (VERIFY_USERS) {
|
||||
try {
|
||||
AuthenticationService authService = new MojangAuthenticationService();
|
||||
authService.setUsername(USERNAME);
|
||||
|
@ -185,7 +186,7 @@ public class MinecraftProtocolTest {
|
|||
|
||||
protocol = new MinecraftProtocol(authService.getSelectedProfile(), authService.getAccessToken());
|
||||
System.out.println("Successfully authenticated user.");
|
||||
} catch(RequestException e) {
|
||||
} catch (RequestException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
@ -200,20 +201,20 @@ public class MinecraftProtocolTest {
|
|||
client.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
|
||||
client.addListener(new SessionAdapter() {
|
||||
@Override
|
||||
public void packetReceived(PacketReceivedEvent event) {
|
||||
if(event.getPacket() instanceof ServerJoinGamePacket) {
|
||||
event.getSession().send(new ClientChatPacket("Hello, this is a test of MCProtocolLib."));
|
||||
} else if(event.getPacket() instanceof ServerChatPacket) {
|
||||
Component message = event.<ServerChatPacket>getPacket().getMessage();
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
session.send(new ServerboundChatPacket("Hello, this is a test of MCProtocolLib."));
|
||||
} else if (packet instanceof ClientboundChatPacket) {
|
||||
Component message = ((ClientboundChatPacket) packet).getMessage();
|
||||
System.out.println("Received Message: " + message);
|
||||
event.getSession().disconnect("Finished");
|
||||
session.disconnect("Finished");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(DisconnectedEvent event) {
|
||||
System.out.println("Disconnected: " + event.getReason());
|
||||
if(event.getCause() != null) {
|
||||
if (event.getCause() != null) {
|
||||
event.getCause().printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
24
pom.xml
24
pom.xml
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>com.github.steveice10</groupId>
|
||||
<artifactId>mcprotocollib</artifactId>
|
||||
<version>1.17.1-2</version>
|
||||
<version>1.18</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MCProtocolLib</name>
|
||||
|
@ -47,6 +47,26 @@
|
|||
</issueManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>opencollab-release-repo</id>
|
||||
<url>https://repo.opencollab.dev/maven-releases/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>opencollab-snapshot-repo</id>
|
||||
<url>https://repo.opencollab.dev/maven-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
|
@ -63,7 +83,7 @@
|
|||
<dependency>
|
||||
<groupId>com.github.steveice10</groupId>
|
||||
<artifactId>packetlib</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -5,30 +5,30 @@ import com.github.steveice10.mc.auth.exception.request.InvalidCredentialsExcepti
|
|||
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
||||
import com.github.steveice10.mc.auth.exception.request.ServiceUnavailableException;
|
||||
import com.github.steveice10.mc.auth.service.SessionService;
|
||||
import com.github.steveice10.mc.protocol.data.SubProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import com.github.steveice10.mc.protocol.data.UnexpectedEncryptionException;
|
||||
import com.github.steveice10.mc.protocol.data.handshake.HandshakeIntent;
|
||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler;
|
||||
import com.github.steveice10.mc.protocol.data.status.handler.ServerPingTimeHandler;
|
||||
import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.client.EncryptionResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.client.LoginStartPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.EncryptionRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginSetCompressionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginSuccessPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.client.StatusPingPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.client.StatusQueryPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.server.StatusPongPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.server.StatusResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundGameProfilePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundHelloPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginCompressionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundHelloPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundKeyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundPongResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundStatusResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundPingRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundStatusRequestPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.PacketSentEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
|
@ -41,21 +41,21 @@ import java.security.NoSuchAlgorithmException;
|
|||
*/
|
||||
@AllArgsConstructor
|
||||
public class ClientListener extends SessionAdapter {
|
||||
private final @NonNull SubProtocol targetSubProtocol;
|
||||
private final @NonNull ProtocolState targetState;
|
||||
|
||||
@Override
|
||||
public void packetReceived(PacketReceivedEvent event) {
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol();
|
||||
if (protocol.getSubProtocol() == SubProtocol.LOGIN) {
|
||||
if (event.getPacket() instanceof EncryptionRequestPacket) {
|
||||
GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY);
|
||||
String accessToken = event.getSession().getFlag(MinecraftConstants.ACCESS_TOKEN_KEY);
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) session.getPacketProtocol();
|
||||
if (protocol.getState() == ProtocolState.LOGIN) {
|
||||
if (packet instanceof ClientboundHelloPacket) {
|
||||
GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);
|
||||
String accessToken = session.getFlag(MinecraftConstants.ACCESS_TOKEN_KEY);
|
||||
|
||||
if (profile == null || accessToken == null) {
|
||||
throw new UnexpectedEncryptionException();
|
||||
}
|
||||
|
||||
EncryptionRequestPacket packet = event.getPacket();
|
||||
ClientboundHelloPacket helloPacket = (ClientboundHelloPacket) packet;
|
||||
SecretKey key;
|
||||
try {
|
||||
KeyGenerator gen = KeyGenerator.getInstance("AES");
|
||||
|
@ -65,79 +65,80 @@ public class ClientListener extends SessionAdapter {
|
|||
throw new IllegalStateException("Failed to generate shared key.", e);
|
||||
}
|
||||
|
||||
SessionService sessionService = event.getSession().getFlag(MinecraftConstants.SESSION_SERVICE_KEY, new SessionService());
|
||||
String serverId = sessionService.getServerId(packet.getServerId(), packet.getPublicKey(), key);
|
||||
SessionService sessionService = session.getFlag(MinecraftConstants.SESSION_SERVICE_KEY, new SessionService());
|
||||
String serverId = sessionService.getServerId(helloPacket.getServerId(), helloPacket.getPublicKey(), key);
|
||||
try {
|
||||
sessionService.joinServer(profile, accessToken, serverId);
|
||||
} catch (ServiceUnavailableException e) {
|
||||
event.getSession().disconnect("Login failed: Authentication service unavailable.", e);
|
||||
session.disconnect("Login failed: Authentication service unavailable.", e);
|
||||
return;
|
||||
} catch (InvalidCredentialsException e) {
|
||||
event.getSession().disconnect("Login failed: Invalid login session.", e);
|
||||
session.disconnect("Login failed: Invalid login session.", e);
|
||||
return;
|
||||
} catch (RequestException e) {
|
||||
event.getSession().disconnect("Login failed: Authentication error: " + e.getMessage(), e);
|
||||
session.disconnect("Login failed: Authentication error: " + e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
event.getSession().send(new EncryptionResponsePacket(packet.getPublicKey(), key, packet.getVerifyToken()));
|
||||
protocol.enableEncryption(key);
|
||||
} else if (event.getPacket() instanceof LoginSuccessPacket) {
|
||||
protocol.setSubProtocol(SubProtocol.GAME, true, event.getSession());
|
||||
} else if (event.getPacket() instanceof LoginDisconnectPacket) {
|
||||
event.getSession().disconnect(event.<LoginDisconnectPacket>getPacket().getReason().toString());
|
||||
} else if (event.getPacket() instanceof LoginSetCompressionPacket) {
|
||||
event.getSession().setCompressionThreshold(event.<LoginSetCompressionPacket>getPacket().getThreshold());
|
||||
session.send(new ServerboundKeyPacket(helloPacket.getPublicKey(), key, helloPacket.getVerifyToken()));
|
||||
session.enableEncryption(protocol.enableEncryption(key));
|
||||
} else if (packet instanceof ClientboundGameProfilePacket) {
|
||||
protocol.setState(ProtocolState.GAME);
|
||||
} else if (packet instanceof ClientboundLoginDisconnectPacket) {
|
||||
session.disconnect(((ClientboundLoginDisconnectPacket) packet).getReason().toString());
|
||||
} else if (packet instanceof ClientboundLoginCompressionPacket) {
|
||||
session.setCompressionThreshold(((ClientboundLoginCompressionPacket) packet).getThreshold());
|
||||
}
|
||||
} else if (protocol.getSubProtocol() == SubProtocol.STATUS) {
|
||||
if (event.getPacket() instanceof StatusResponsePacket) {
|
||||
ServerStatusInfo info = event.<StatusResponsePacket>getPacket().getInfo();
|
||||
ServerInfoHandler handler = event.getSession().getFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY);
|
||||
} else if (protocol.getState() == ProtocolState.STATUS) {
|
||||
if (packet instanceof ClientboundStatusResponsePacket) {
|
||||
ServerStatusInfo info = ((ClientboundStatusResponsePacket) packet).getInfo();
|
||||
ServerInfoHandler handler = session.getFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY);
|
||||
if (handler != null) {
|
||||
handler.handle(event.getSession(), info);
|
||||
handler.handle(session, info);
|
||||
}
|
||||
|
||||
event.getSession().send(new StatusPingPacket(System.currentTimeMillis()));
|
||||
} else if (event.getPacket() instanceof StatusPongPacket) {
|
||||
long time = System.currentTimeMillis() - event.<StatusPongPacket>getPacket().getPingTime();
|
||||
ServerPingTimeHandler handler = event.getSession().getFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY);
|
||||
session.send(new ServerboundPingRequestPacket(System.currentTimeMillis()));
|
||||
} else if (packet instanceof ClientboundPongResponsePacket) {
|
||||
long time = System.currentTimeMillis() - ((ClientboundPongResponsePacket) packet).getPingTime();
|
||||
ServerPingTimeHandler handler = session.getFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY);
|
||||
if (handler != null) {
|
||||
handler.handle(event.getSession(), time);
|
||||
handler.handle(session, time);
|
||||
}
|
||||
|
||||
event.getSession().disconnect("Finished");
|
||||
session.disconnect("Finished");
|
||||
}
|
||||
} else if (protocol.getSubProtocol() == SubProtocol.GAME) {
|
||||
if (event.getPacket() instanceof ServerKeepAlivePacket && event.getSession().getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
|
||||
event.getSession().send(new ClientKeepAlivePacket(event.<ServerKeepAlivePacket>getPacket().getPingId()));
|
||||
} else if (event.getPacket() instanceof ServerDisconnectPacket) {
|
||||
event.getSession().disconnect(event.<ServerDisconnectPacket>getPacket().getReason().toString());
|
||||
} else if (protocol.getState() == ProtocolState.GAME) {
|
||||
if (packet instanceof ClientboundKeepAlivePacket && session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
|
||||
session.send(new ServerboundKeepAlivePacket(((ClientboundKeepAlivePacket) packet).getPingId()));
|
||||
} else if (packet instanceof ClientboundDisconnectPacket) {
|
||||
session.disconnect(((ClientboundDisconnectPacket) packet).getReason().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetSent(PacketSentEvent event) {
|
||||
if (event.getPacket() instanceof HandshakePacket) {
|
||||
public void packetSent(Session session, Packet packet) {
|
||||
if (packet instanceof ClientIntentionPacket) {
|
||||
// Once the HandshakePacket has been sent, switch to the next protocol mode.
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol();
|
||||
protocol.setSubProtocol(this.targetSubProtocol, true, event.getSession());
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) session.getPacketProtocol();
|
||||
protocol.setState(this.targetState);
|
||||
|
||||
if (this.targetSubProtocol == SubProtocol.LOGIN) {
|
||||
GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY);
|
||||
event.getSession().send(new LoginStartPacket(profile.getName()));
|
||||
if (this.targetState == ProtocolState.LOGIN) {
|
||||
GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);
|
||||
session.send(new ServerboundHelloPacket(profile.getName()));
|
||||
} else {
|
||||
event.getSession().send(new StatusQueryPacket());
|
||||
session.send(new ServerboundStatusRequestPacket());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected(ConnectedEvent event) {
|
||||
if (this.targetSubProtocol == SubProtocol.LOGIN) {
|
||||
event.getSession().send(new HandshakePacket(MinecraftConstants.PROTOCOL_VERSION, event.getSession().getHost(), event.getSession().getPort(), HandshakeIntent.LOGIN));
|
||||
} else if (this.targetSubProtocol == SubProtocol.STATUS) {
|
||||
event.getSession().send(new HandshakePacket(MinecraftConstants.PROTOCOL_VERSION, event.getSession().getHost(), event.getSession().getPort(), HandshakeIntent.STATUS));
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol();
|
||||
if (this.targetState == ProtocolState.LOGIN) {
|
||||
event.getSession().send(new ClientIntentionPacket(protocol.getCodec().getProtocolVersion(), event.getSession().getHost(), event.getSession().getPort(), HandshakeIntent.LOGIN));
|
||||
} else if (this.targetState == ProtocolState.STATUS) {
|
||||
event.getSession().send(new ClientIntentionPacket(protocol.getCodec().getProtocolVersion(), event.getSession().getHost(), event.getSession().getPort(), HandshakeIntent.STATUS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,23 +2,13 @@ package com.github.steveice10.mc.protocol;
|
|||
|
||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
import com.github.steveice10.mc.auth.service.SessionService;
|
||||
import com.github.steveice10.packetlib.packet.DefaultPacketHeader;
|
||||
import com.github.steveice10.packetlib.packet.PacketHeader;
|
||||
|
||||
/**
|
||||
* Class containing various constants for Minecraft sessions.
|
||||
*/
|
||||
public final class MinecraftConstants {
|
||||
// General Constants
|
||||
|
||||
/**
|
||||
* Current supported game version.
|
||||
*/
|
||||
public static final String GAME_VERSION = "1.17.1";
|
||||
|
||||
/**
|
||||
* Current supported protocol version.
|
||||
*/
|
||||
public static final int PROTOCOL_VERSION = 756;
|
||||
|
||||
// General Key Constants
|
||||
|
||||
/**
|
||||
|
@ -83,6 +73,16 @@ public final class MinecraftConstants {
|
|||
*/
|
||||
public static final String SERVER_COMPRESSION_THRESHOLD = "compression-threshold";
|
||||
|
||||
/**
|
||||
* The packet header used by Minecraft.
|
||||
*/
|
||||
public static final PacketHeader PACKET_HEADER = new DefaultPacketHeader();
|
||||
|
||||
/**
|
||||
* The SRV Record prefix used by Minecraft.
|
||||
*/
|
||||
public static final String SRV_RECORD_PREFIX = "_minecraft";
|
||||
|
||||
private MinecraftConstants() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,176 +1,15 @@
|
|||
package com.github.steveice10.mc.protocol;
|
||||
|
||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
import com.github.steveice10.mc.protocol.data.SubProtocol;
|
||||
import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientLockDifficultyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPongPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientResourcePackStatusPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientSetDifficultyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientTabCompletePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerAbilitiesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerChangeHeldItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerMovementPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientAdvancementTabPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientClickWindowButtonPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCraftingBookStatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientDisplayedRecipePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientEditBookPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientMoveItemToHotbarPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientPrepareCraftingGridPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientSelectTradePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientSetBeaconEffectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateCommandBlockMinecartPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateCommandBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateJigsawBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateStructureBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientWindowActionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientBlockNBTRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientEntityNBTRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientGenerateStructuresPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSpectatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSteerBoatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSteerVehiclePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientUpdateSignPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerAdvancementTabPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerAdvancementsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerBossBarPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareCommandsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareRecipesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareTagsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDifficultyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerEntitySoundEffectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPingPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListDataPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerResourcePackSendPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerSetCooldownPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerStatisticsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerStopSoundPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerSwitchCameraPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTabCompletePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerUnlockRecipesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAttachPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityCollectItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEquipmentPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRemoveEffectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntitySetPassengersPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerRemoveEntitiesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerVehicleMovePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerChangeHeldItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerCombatEndPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerCombatEnterPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerCombatKillPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerFacingPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerSetExperiencePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnLivingEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerClearTitlesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetActionBarTextPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetSubtitleTextPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetTitleTextPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetTitlesAnimationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerCloseWindowPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenBookPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenHorseWindowPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerPreparedCraftingGridPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerTradeListPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowPropertyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerAddVibrationSignalPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockBreakAnimPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockValuePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerExplosionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMapDataPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNBTResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerOpenTileEntityEditorPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlayBuiltinSoundPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlayEffectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerSpawnParticlePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerSpawnPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUnloadChunkPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateLightPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewDistancePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.border.ServerInitializeBorderPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.border.ServerSetBorderCenterPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.border.ServerSetBorderLerpSizePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.border.ServerSetBorderSizePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.border.ServerSetBorderWarningDelayPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.border.ServerSetBorderWarningDistancePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.client.EncryptionResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.client.LoginPluginResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.client.LoginStartPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.EncryptionRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginPluginRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginSetCompressionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginSuccessPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.client.StatusPingPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.client.StatusQueryPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.server.StatusPongPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.server.StatusResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.codec.MinecraftCodec;
|
||||
import com.github.steveice10.mc.protocol.codec.PacketCodec;
|
||||
import com.github.steveice10.mc.protocol.codec.PacketStateCodec;
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import com.github.steveice10.packetlib.Server;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.crypt.AESEncryption;
|
||||
import com.github.steveice10.packetlib.crypt.PacketEncryption;
|
||||
import com.github.steveice10.packetlib.packet.DefaultPacketHeader;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.packet.PacketHeader;
|
||||
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
||||
|
@ -178,20 +17,27 @@ import lombok.Getter;
|
|||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.Key;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Implements the Minecraft protocol.
|
||||
*/
|
||||
public class MinecraftProtocol extends PacketProtocol {
|
||||
private SubProtocol subProtocol = SubProtocol.HANDSHAKE;
|
||||
private final PacketHeader packetHeader = new DefaultPacketHeader();
|
||||
private AESEncryption encryption;
|
||||
|
||||
private SubProtocol targetSubProtocol;
|
||||
/**
|
||||
* The codec used for the Minecraft protocol.
|
||||
*/
|
||||
@Getter
|
||||
private final PacketCodec codec;
|
||||
|
||||
private ProtocolState state;
|
||||
private PacketStateCodec stateCodec;
|
||||
|
||||
private final ProtocolState targetState;
|
||||
|
||||
/**
|
||||
* The player's identity.
|
||||
|
@ -216,7 +62,19 @@ public class MinecraftProtocol extends PacketProtocol {
|
|||
* Constructs a new MinecraftProtocol instance for making status queries.
|
||||
*/
|
||||
public MinecraftProtocol() {
|
||||
this.targetSubProtocol = SubProtocol.STATUS;
|
||||
this(MinecraftCodec.CODEC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MinecraftProtocol instance for making status queries.
|
||||
*
|
||||
* @param codec The packet codec to use.
|
||||
*/
|
||||
public MinecraftProtocol(PacketCodec codec) {
|
||||
this.codec = codec;
|
||||
this.targetState = ProtocolState.STATUS;
|
||||
|
||||
this.setState(ProtocolState.HANDSHAKE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,6 +86,16 @@ public class MinecraftProtocol extends PacketProtocol {
|
|||
this(new GameProfile((UUID) null, username), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MinecraftProtocol instance for logging in using offline mode.
|
||||
*
|
||||
* @param codec The packet codec to use.
|
||||
* @param username Username to use.
|
||||
*/
|
||||
public MinecraftProtocol(@NonNull PacketCodec codec, @NonNull String username) {
|
||||
this(codec, new GameProfile((UUID) null, username), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MinecraftProtocol instance for logging in.
|
||||
*
|
||||
|
@ -235,24 +103,33 @@ public class MinecraftProtocol extends PacketProtocol {
|
|||
* @param accessToken Access token to use, or null if using offline mode.
|
||||
*/
|
||||
public MinecraftProtocol(@NonNull GameProfile profile, String accessToken) {
|
||||
this.targetSubProtocol = SubProtocol.LOGIN;
|
||||
this(MinecraftCodec.CODEC, profile, accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MinecraftProtocol instance for logging in.
|
||||
*
|
||||
* @param codec The packet codec to use.
|
||||
* @param profile GameProfile to use.
|
||||
* @param accessToken Access token to use, or null if using offline mode.
|
||||
*/
|
||||
public MinecraftProtocol(@NonNull PacketCodec codec, @NonNull GameProfile profile, String accessToken) {
|
||||
this.codec = codec;
|
||||
this.targetState = ProtocolState.LOGIN;
|
||||
this.profile = profile;
|
||||
this.accessToken = accessToken;
|
||||
|
||||
this.setState(ProtocolState.HANDSHAKE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSRVRecordPrefix() {
|
||||
return "_minecraft";
|
||||
return MinecraftConstants.SRV_RECORD_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketHeader getPacketHeader() {
|
||||
return this.packetHeader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketEncryption getEncryption() {
|
||||
return this.encryption;
|
||||
return MinecraftConstants.PACKET_HEADER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -260,259 +137,81 @@ public class MinecraftProtocol extends PacketProtocol {
|
|||
session.setFlag(MinecraftConstants.PROFILE_KEY, this.profile);
|
||||
session.setFlag(MinecraftConstants.ACCESS_TOKEN_KEY, this.accessToken);
|
||||
|
||||
this.setSubProtocol(SubProtocol.HANDSHAKE, true, session);
|
||||
this.setState(ProtocolState.HANDSHAKE);
|
||||
|
||||
if (this.useDefaultListeners) {
|
||||
session.addListener(new ClientListener(this.targetSubProtocol));
|
||||
session.addListener(new ClientListener(this.targetState));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newServerSession(Server server, Session session) {
|
||||
this.setSubProtocol(SubProtocol.HANDSHAKE, false, session);
|
||||
this.setState(ProtocolState.HANDSHAKE);
|
||||
|
||||
if (this.useDefaultListeners) {
|
||||
session.addListener(new ServerListener());
|
||||
}
|
||||
}
|
||||
|
||||
protected void enableEncryption(Key key) {
|
||||
protected PacketEncryption enableEncryption(Key key) {
|
||||
try {
|
||||
this.encryption = new AESEncryption(key);
|
||||
return new AESEncryption(key);
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new Error("Failed to enable protocol encryption.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current {@link SubProtocol} the client is in.
|
||||
* Gets the current {@link ProtocolState} the client is in.
|
||||
*
|
||||
* @return The current {@link SubProtocol}.
|
||||
* @return The current {@link ProtocolState}.
|
||||
*/
|
||||
public SubProtocol getSubProtocol() {
|
||||
return this.subProtocol;
|
||||
public ProtocolState getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
protected void setSubProtocol(SubProtocol subProtocol, boolean client, Session session) {
|
||||
this.clearPackets();
|
||||
switch (subProtocol) {
|
||||
case HANDSHAKE:
|
||||
if (client) {
|
||||
this.initClientHandshake();
|
||||
} else {
|
||||
this.initServerHandshake();
|
||||
}
|
||||
|
||||
break;
|
||||
case LOGIN:
|
||||
if (client) {
|
||||
this.initLogin(this::registerIncoming, this::registerOutgoing);
|
||||
} else {
|
||||
this.initLogin(this::registerOutgoing, this::registerIncoming);
|
||||
}
|
||||
|
||||
break;
|
||||
case GAME:
|
||||
if (client) {
|
||||
this.initGame(this::registerIncoming, this::registerOutgoing);
|
||||
} else {
|
||||
this.initGame(this::registerOutgoing, this::registerIncoming);
|
||||
}
|
||||
|
||||
break;
|
||||
case STATUS:
|
||||
if (client) {
|
||||
this.initStatus(this::registerIncoming, this::registerOutgoing);
|
||||
} else {
|
||||
this.initStatus(this::registerOutgoing, this::registerIncoming);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
this.subProtocol = subProtocol;
|
||||
protected void setState(ProtocolState state) {
|
||||
this.state = state;
|
||||
this.stateCodec = this.codec.getCodec(state);
|
||||
}
|
||||
|
||||
private void initClientHandshake() {
|
||||
this.registerOutgoing(0, HandshakePacket.class);
|
||||
@Override
|
||||
public Packet createClientboundPacket(int id, NetInput in) throws IOException {
|
||||
return this.stateCodec.createClientboundPacket(id, in);
|
||||
}
|
||||
|
||||
private void initServerHandshake() {
|
||||
this.registerIncoming(0, HandshakePacket.class);
|
||||
@Override
|
||||
public int getClientboundId(Class<? extends Packet> packetClass) {
|
||||
return this.stateCodec.getClientboundId(packetClass);
|
||||
}
|
||||
|
||||
private void initLogin(BiConsumer<Integer, Class<? extends Packet>> clientboundPackets, BiConsumer<Integer, Class<? extends Packet>> serverboundPackets) {
|
||||
clientboundPackets.accept(0x00, LoginDisconnectPacket.class);
|
||||
clientboundPackets.accept(0x01, EncryptionRequestPacket.class);
|
||||
clientboundPackets.accept(0x02, LoginSuccessPacket.class);
|
||||
clientboundPackets.accept(0x03, LoginSetCompressionPacket.class);
|
||||
clientboundPackets.accept(0x04, LoginPluginRequestPacket.class);
|
||||
|
||||
serverboundPackets.accept(0x00, LoginStartPacket.class);
|
||||
serverboundPackets.accept(0x01, EncryptionResponsePacket.class);
|
||||
serverboundPackets.accept(0x02, LoginPluginResponsePacket.class);
|
||||
@Override
|
||||
public int getClientboundId(Packet packet) {
|
||||
return this.stateCodec.getClientboundId(packet);
|
||||
}
|
||||
|
||||
private void initGame(BiConsumer<Integer, Class<? extends Packet>> clientboundPackets, BiConsumer<Integer, Class<? extends Packet>> serverboundPackets) {
|
||||
clientboundPackets.accept(0x00, ServerSpawnEntityPacket.class);
|
||||
clientboundPackets.accept(0x01, ServerSpawnExpOrbPacket.class);
|
||||
clientboundPackets.accept(0x02, ServerSpawnLivingEntityPacket.class);
|
||||
clientboundPackets.accept(0x03, ServerSpawnPaintingPacket.class);
|
||||
clientboundPackets.accept(0x04, ServerSpawnPlayerPacket.class);
|
||||
clientboundPackets.accept(0x05, ServerAddVibrationSignalPacket.class);
|
||||
clientboundPackets.accept(0x06, ServerEntityAnimationPacket.class);
|
||||
clientboundPackets.accept(0x07, ServerStatisticsPacket.class);
|
||||
clientboundPackets.accept(0x08, ServerPlayerActionAckPacket.class);
|
||||
clientboundPackets.accept(0x09, ServerBlockBreakAnimPacket.class);
|
||||
clientboundPackets.accept(0x0A, ServerUpdateTileEntityPacket.class);
|
||||
clientboundPackets.accept(0x0B, ServerBlockValuePacket.class);
|
||||
clientboundPackets.accept(0x0C, ServerBlockChangePacket.class);
|
||||
clientboundPackets.accept(0x0D, ServerBossBarPacket.class);
|
||||
clientboundPackets.accept(0x0E, ServerDifficultyPacket.class);
|
||||
clientboundPackets.accept(0x0F, ServerChatPacket.class);
|
||||
clientboundPackets.accept(0x10, ServerClearTitlesPacket.class);
|
||||
clientboundPackets.accept(0x11, ServerTabCompletePacket.class);
|
||||
clientboundPackets.accept(0x12, ServerDeclareCommandsPacket.class);
|
||||
clientboundPackets.accept(0x13, ServerCloseWindowPacket.class);
|
||||
clientboundPackets.accept(0x14, ServerWindowItemsPacket.class);
|
||||
clientboundPackets.accept(0x15, ServerWindowPropertyPacket.class);
|
||||
clientboundPackets.accept(0x16, ServerSetSlotPacket.class);
|
||||
clientboundPackets.accept(0x17, ServerSetCooldownPacket.class);
|
||||
clientboundPackets.accept(0x18, ServerPluginMessagePacket.class);
|
||||
clientboundPackets.accept(0x19, ServerPlaySoundPacket.class);
|
||||
clientboundPackets.accept(0x1A, ServerDisconnectPacket.class);
|
||||
clientboundPackets.accept(0x1B, ServerEntityStatusPacket.class);
|
||||
clientboundPackets.accept(0x1C, ServerExplosionPacket.class);
|
||||
clientboundPackets.accept(0x1D, ServerUnloadChunkPacket.class);
|
||||
clientboundPackets.accept(0x1E, ServerNotifyClientPacket.class);
|
||||
clientboundPackets.accept(0x1F, ServerOpenHorseWindowPacket.class);
|
||||
clientboundPackets.accept(0x20, ServerInitializeBorderPacket.class);
|
||||
clientboundPackets.accept(0x21, ServerKeepAlivePacket.class);
|
||||
clientboundPackets.accept(0x22, ServerChunkDataPacket.class);
|
||||
clientboundPackets.accept(0x23, ServerPlayEffectPacket.class);
|
||||
clientboundPackets.accept(0x24, ServerSpawnParticlePacket.class);
|
||||
clientboundPackets.accept(0x25, ServerUpdateLightPacket.class);
|
||||
clientboundPackets.accept(0x26, ServerJoinGamePacket.class);
|
||||
clientboundPackets.accept(0x27, ServerMapDataPacket.class);
|
||||
clientboundPackets.accept(0x28, ServerTradeListPacket.class);
|
||||
clientboundPackets.accept(0x29, ServerEntityPositionPacket.class);
|
||||
clientboundPackets.accept(0x2A, ServerEntityPositionRotationPacket.class);
|
||||
clientboundPackets.accept(0x2B, ServerEntityRotationPacket.class);
|
||||
clientboundPackets.accept(0x2C, ServerVehicleMovePacket.class);
|
||||
clientboundPackets.accept(0x2D, ServerOpenBookPacket.class);
|
||||
clientboundPackets.accept(0x2E, ServerOpenWindowPacket.class);
|
||||
clientboundPackets.accept(0x2F, ServerOpenTileEntityEditorPacket.class);
|
||||
clientboundPackets.accept(0x30, ServerPingPacket.class);
|
||||
clientboundPackets.accept(0x31, ServerPreparedCraftingGridPacket.class);
|
||||
clientboundPackets.accept(0x32, ServerPlayerAbilitiesPacket.class);
|
||||
clientboundPackets.accept(0x33, ServerPlayerCombatEndPacket.class);
|
||||
clientboundPackets.accept(0x34, ServerPlayerCombatEnterPacket.class);
|
||||
clientboundPackets.accept(0x35, ServerPlayerCombatKillPacket.class);
|
||||
clientboundPackets.accept(0x36, ServerPlayerListEntryPacket.class);
|
||||
clientboundPackets.accept(0x37, ServerPlayerFacingPacket.class);
|
||||
clientboundPackets.accept(0x38, ServerPlayerPositionRotationPacket.class);
|
||||
clientboundPackets.accept(0x39, ServerUnlockRecipesPacket.class);
|
||||
clientboundPackets.accept(0x3A, ServerRemoveEntitiesPacket.class);
|
||||
clientboundPackets.accept(0x3B, ServerEntityRemoveEffectPacket.class);
|
||||
clientboundPackets.accept(0x3C, ServerResourcePackSendPacket.class);
|
||||
clientboundPackets.accept(0x3D, ServerRespawnPacket.class);
|
||||
clientboundPackets.accept(0x3E, ServerEntityHeadLookPacket.class);
|
||||
clientboundPackets.accept(0x3F, ServerMultiBlockChangePacket.class);
|
||||
clientboundPackets.accept(0x40, ServerAdvancementTabPacket.class);
|
||||
clientboundPackets.accept(0x41, ServerSetActionBarTextPacket.class);
|
||||
clientboundPackets.accept(0x42, ServerSetBorderCenterPacket.class);
|
||||
clientboundPackets.accept(0x43, ServerSetBorderLerpSizePacket.class);
|
||||
clientboundPackets.accept(0x44, ServerSetBorderSizePacket.class);
|
||||
clientboundPackets.accept(0x45, ServerSetBorderWarningDelayPacket.class);
|
||||
clientboundPackets.accept(0x46, ServerSetBorderWarningDistancePacket.class);
|
||||
clientboundPackets.accept(0x47, ServerSwitchCameraPacket.class);
|
||||
clientboundPackets.accept(0x48, ServerPlayerChangeHeldItemPacket.class);
|
||||
clientboundPackets.accept(0x49, ServerUpdateViewPositionPacket.class);
|
||||
clientboundPackets.accept(0x4A, ServerUpdateViewDistancePacket.class);
|
||||
clientboundPackets.accept(0x4B, ServerSpawnPositionPacket.class);
|
||||
clientboundPackets.accept(0x4C, ServerDisplayScoreboardPacket.class);
|
||||
clientboundPackets.accept(0x4D, ServerEntityMetadataPacket.class);
|
||||
clientboundPackets.accept(0x4E, ServerEntityAttachPacket.class);
|
||||
clientboundPackets.accept(0x4F, ServerEntityVelocityPacket.class);
|
||||
clientboundPackets.accept(0x50, ServerEntityEquipmentPacket.class);
|
||||
clientboundPackets.accept(0x51, ServerPlayerSetExperiencePacket.class);
|
||||
clientboundPackets.accept(0x52, ServerPlayerHealthPacket.class);
|
||||
clientboundPackets.accept(0x53, ServerScoreboardObjectivePacket.class);
|
||||
clientboundPackets.accept(0x54, ServerEntitySetPassengersPacket.class);
|
||||
clientboundPackets.accept(0x55, ServerTeamPacket.class);
|
||||
clientboundPackets.accept(0x56, ServerUpdateScorePacket.class);
|
||||
clientboundPackets.accept(0x57, ServerSetSubtitleTextPacket.class);
|
||||
clientboundPackets.accept(0x58, ServerUpdateTimePacket.class);
|
||||
clientboundPackets.accept(0x59, ServerSetTitleTextPacket.class);
|
||||
clientboundPackets.accept(0x5A, ServerSetTitlesAnimationPacket.class);
|
||||
clientboundPackets.accept(0x5B, ServerEntitySoundEffectPacket.class);
|
||||
clientboundPackets.accept(0x5C, ServerPlayBuiltinSoundPacket.class);
|
||||
clientboundPackets.accept(0x5D, ServerStopSoundPacket.class);
|
||||
clientboundPackets.accept(0x5E, ServerPlayerListDataPacket.class);
|
||||
clientboundPackets.accept(0x5F, ServerNBTResponsePacket.class);
|
||||
clientboundPackets.accept(0x60, ServerEntityCollectItemPacket.class);
|
||||
clientboundPackets.accept(0x61, ServerEntityTeleportPacket.class);
|
||||
clientboundPackets.accept(0x62, ServerAdvancementsPacket.class);
|
||||
clientboundPackets.accept(0x63, ServerEntityPropertiesPacket.class);
|
||||
clientboundPackets.accept(0x64, ServerEntityEffectPacket.class);
|
||||
clientboundPackets.accept(0x65, ServerDeclareRecipesPacket.class);
|
||||
clientboundPackets.accept(0x66, ServerDeclareTagsPacket.class);
|
||||
|
||||
serverboundPackets.accept(0x00, ClientTeleportConfirmPacket.class);
|
||||
serverboundPackets.accept(0x01, ClientBlockNBTRequestPacket.class);
|
||||
serverboundPackets.accept(0x02, ClientSetDifficultyPacket.class);
|
||||
serverboundPackets.accept(0x03, ClientChatPacket.class);
|
||||
serverboundPackets.accept(0x04, ClientRequestPacket.class);
|
||||
serverboundPackets.accept(0x05, ClientSettingsPacket.class);
|
||||
serverboundPackets.accept(0x06, ClientTabCompletePacket.class);
|
||||
serverboundPackets.accept(0x07, ClientClickWindowButtonPacket.class);
|
||||
serverboundPackets.accept(0x08, ClientWindowActionPacket.class);
|
||||
serverboundPackets.accept(0x09, ClientCloseWindowPacket.class);
|
||||
serverboundPackets.accept(0x0A, ClientPluginMessagePacket.class);
|
||||
serverboundPackets.accept(0x0B, ClientEditBookPacket.class);
|
||||
serverboundPackets.accept(0x0C, ClientEntityNBTRequestPacket.class);
|
||||
serverboundPackets.accept(0x0D, ClientPlayerInteractEntityPacket.class);
|
||||
serverboundPackets.accept(0x0E, ClientGenerateStructuresPacket.class);
|
||||
serverboundPackets.accept(0x0F, ClientKeepAlivePacket.class);
|
||||
serverboundPackets.accept(0x10, ClientLockDifficultyPacket.class);
|
||||
serverboundPackets.accept(0x11, ClientPlayerPositionPacket.class);
|
||||
serverboundPackets.accept(0x12, ClientPlayerPositionRotationPacket.class);
|
||||
serverboundPackets.accept(0x13, ClientPlayerRotationPacket.class);
|
||||
serverboundPackets.accept(0x14, ClientPlayerMovementPacket.class);
|
||||
serverboundPackets.accept(0x15, ClientVehicleMovePacket.class);
|
||||
serverboundPackets.accept(0x16, ClientSteerBoatPacket.class);
|
||||
serverboundPackets.accept(0x17, ClientMoveItemToHotbarPacket.class);
|
||||
serverboundPackets.accept(0x18, ClientPrepareCraftingGridPacket.class);
|
||||
serverboundPackets.accept(0x19, ClientPlayerAbilitiesPacket.class);
|
||||
serverboundPackets.accept(0x1A, ClientPlayerActionPacket.class);
|
||||
serverboundPackets.accept(0x1B, ClientPlayerStatePacket.class);
|
||||
serverboundPackets.accept(0x1C, ClientSteerVehiclePacket.class);
|
||||
serverboundPackets.accept(0x1D, ClientPongPacket.class);
|
||||
serverboundPackets.accept(0x1E, ClientCraftingBookStatePacket.class);
|
||||
serverboundPackets.accept(0x1F, ClientDisplayedRecipePacket.class);
|
||||
serverboundPackets.accept(0x20, ClientRenameItemPacket.class);
|
||||
serverboundPackets.accept(0x21, ClientResourcePackStatusPacket.class);
|
||||
serverboundPackets.accept(0x22, ClientAdvancementTabPacket.class);
|
||||
serverboundPackets.accept(0x23, ClientSelectTradePacket.class);
|
||||
serverboundPackets.accept(0x24, ClientSetBeaconEffectPacket.class);
|
||||
serverboundPackets.accept(0x25, ClientPlayerChangeHeldItemPacket.class);
|
||||
serverboundPackets.accept(0x26, ClientUpdateCommandBlockPacket.class);
|
||||
serverboundPackets.accept(0x27, ClientUpdateCommandBlockMinecartPacket.class);
|
||||
serverboundPackets.accept(0x28, ClientCreativeInventoryActionPacket.class);
|
||||
serverboundPackets.accept(0x29, ClientUpdateJigsawBlockPacket.class);
|
||||
serverboundPackets.accept(0x2A, ClientUpdateStructureBlockPacket.class);
|
||||
serverboundPackets.accept(0x2B, ClientUpdateSignPacket.class);
|
||||
serverboundPackets.accept(0x2C, ClientPlayerSwingArmPacket.class);
|
||||
serverboundPackets.accept(0x2D, ClientSpectatePacket.class);
|
||||
serverboundPackets.accept(0x2E, ClientPlayerPlaceBlockPacket.class);
|
||||
serverboundPackets.accept(0x2F, ClientPlayerUseItemPacket.class);
|
||||
@Override
|
||||
public Class<? extends Packet> getClientboundClass(int id) {
|
||||
return this.stateCodec.getClientboundClass(id);
|
||||
}
|
||||
|
||||
private void initStatus(BiConsumer<Integer, Class<? extends Packet>> clientboundPackets, BiConsumer<Integer, Class<? extends Packet>> serverboundPackets) {
|
||||
clientboundPackets.accept(0x00, StatusResponsePacket.class);
|
||||
clientboundPackets.accept(0x01, StatusPongPacket.class);
|
||||
@Override
|
||||
public Packet createServerboundPacket(int id, NetInput in) throws IOException {
|
||||
return this.stateCodec.createServerboundPacket(id, in);
|
||||
}
|
||||
|
||||
serverboundPackets.accept(0x00, StatusQueryPacket.class);
|
||||
serverboundPackets.accept(0x01, StatusPingPacket.class);
|
||||
@Override
|
||||
public int getServerboundId(Class<? extends Packet> packetClass) {
|
||||
return this.stateCodec.getServerboundId(packetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getServerboundId(Packet packet) {
|
||||
return this.stateCodec.getServerboundId(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Packet> getServerboundClass(int id) {
|
||||
return this.stateCodec.getServerboundClass(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,31 +3,30 @@ package com.github.steveice10.mc.protocol;
|
|||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
||||
import com.github.steveice10.mc.auth.service.SessionService;
|
||||
import com.github.steveice10.mc.protocol.data.SubProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import com.github.steveice10.mc.protocol.data.status.PlayerInfo;
|
||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||
import com.github.steveice10.mc.protocol.data.status.VersionInfo;
|
||||
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoBuilder;
|
||||
import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.client.EncryptionResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.client.LoginStartPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.EncryptionRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginSetCompressionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.server.LoginSuccessPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.client.StatusPingPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.client.StatusQueryPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.server.StatusPongPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.server.StatusResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundGameProfilePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundHelloPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginCompressionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundHelloPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundKeyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundPongResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundStatusResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundPingRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundStatusRequestPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectingEvent;
|
||||
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.PacketSentEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
@ -75,97 +74,95 @@ public class ServerListener extends SessionAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived(PacketReceivedEvent event) {
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol();
|
||||
if (protocol.getSubProtocol() == SubProtocol.HANDSHAKE) {
|
||||
if (event.getPacket() instanceof HandshakePacket) {
|
||||
HandshakePacket packet = event.getPacket();
|
||||
switch (packet.getIntent()) {
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) session.getPacketProtocol();
|
||||
if (protocol.getState() == ProtocolState.HANDSHAKE) {
|
||||
if (packet instanceof ClientIntentionPacket) {
|
||||
ClientIntentionPacket intentionPacket = (ClientIntentionPacket) packet;
|
||||
switch (intentionPacket.getIntent()) {
|
||||
case STATUS:
|
||||
protocol.setSubProtocol(SubProtocol.STATUS, false, event.getSession());
|
||||
protocol.setState(ProtocolState.STATUS);
|
||||
break;
|
||||
case LOGIN:
|
||||
protocol.setSubProtocol(SubProtocol.LOGIN, false, event.getSession());
|
||||
if (packet.getProtocolVersion() > MinecraftConstants.PROTOCOL_VERSION) {
|
||||
event.getSession().disconnect("Outdated server! I'm still on " + MinecraftConstants.GAME_VERSION + ".");
|
||||
} else if (packet.getProtocolVersion() < MinecraftConstants.PROTOCOL_VERSION) {
|
||||
event.getSession().disconnect("Outdated client! Please use " + MinecraftConstants.GAME_VERSION + ".");
|
||||
protocol.setState(ProtocolState.LOGIN);
|
||||
if (intentionPacket.getProtocolVersion() > protocol.getCodec().getProtocolVersion()) {
|
||||
session.disconnect("Outdated server! I'm still on " + protocol.getCodec().getMinecraftVersion() + ".");
|
||||
} else if (intentionPacket.getProtocolVersion() < protocol.getCodec().getProtocolVersion()) {
|
||||
session.disconnect("Outdated client! Please use " + protocol.getCodec().getMinecraftVersion() + ".");
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Invalid client intent: " + packet.getIntent());
|
||||
throw new UnsupportedOperationException("Invalid client intent: " + intentionPacket.getIntent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (protocol.getSubProtocol() == SubProtocol.LOGIN) {
|
||||
if (event.getPacket() instanceof LoginStartPacket) {
|
||||
this.username = event.<LoginStartPacket>getPacket().getUsername();
|
||||
if (protocol.getState() == ProtocolState.LOGIN) {
|
||||
if (packet instanceof ServerboundHelloPacket) {
|
||||
this.username = ((ServerboundHelloPacket) packet).getUsername();
|
||||
|
||||
if (event.getSession().getFlag(MinecraftConstants.VERIFY_USERS_KEY, true)) {
|
||||
event.getSession().send(new EncryptionRequestPacket(SERVER_ID, KEY_PAIR.getPublic(), this.verifyToken));
|
||||
if (session.getFlag(MinecraftConstants.VERIFY_USERS_KEY, true)) {
|
||||
session.send(new ClientboundHelloPacket(SERVER_ID, KEY_PAIR.getPublic(), this.verifyToken));
|
||||
} else {
|
||||
new Thread(new UserAuthTask(event.getSession(), null)).start();
|
||||
new Thread(new UserAuthTask(session, null)).start();
|
||||
}
|
||||
} else if (event.getPacket() instanceof EncryptionResponsePacket) {
|
||||
EncryptionResponsePacket packet = event.getPacket();
|
||||
} else if (packet instanceof ServerboundKeyPacket) {
|
||||
ServerboundKeyPacket keyPacket = (ServerboundKeyPacket) packet;
|
||||
PrivateKey privateKey = KEY_PAIR.getPrivate();
|
||||
if (!Arrays.equals(this.verifyToken, packet.getVerifyToken(privateKey))) {
|
||||
event.getSession().disconnect("Invalid nonce!");
|
||||
if (!Arrays.equals(this.verifyToken, keyPacket.getVerifyToken(privateKey))) {
|
||||
session.disconnect("Invalid nonce!");
|
||||
return;
|
||||
}
|
||||
|
||||
SecretKey key = packet.getSecretKey(privateKey);
|
||||
SecretKey key = keyPacket.getSecretKey(privateKey);
|
||||
protocol.enableEncryption(key);
|
||||
new Thread(new UserAuthTask(event.getSession(), key)).start();
|
||||
new Thread(new UserAuthTask(session, key)).start();
|
||||
}
|
||||
}
|
||||
|
||||
if (protocol.getSubProtocol() == SubProtocol.STATUS) {
|
||||
if (event.getPacket() instanceof StatusQueryPacket) {
|
||||
ServerInfoBuilder builder = event.getSession().getFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY);
|
||||
if (protocol.getState() == ProtocolState.STATUS) {
|
||||
if (packet instanceof ServerboundStatusRequestPacket) {
|
||||
ServerInfoBuilder builder = session.getFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY);
|
||||
if (builder == null) {
|
||||
builder = session -> new ServerStatusInfo(
|
||||
VersionInfo.CURRENT,
|
||||
builder = $ -> new ServerStatusInfo(
|
||||
new VersionInfo(protocol.getCodec().getMinecraftVersion(), protocol.getCodec().getProtocolVersion()),
|
||||
new PlayerInfo(0, 20, new GameProfile[0]),
|
||||
Component.text("A Minecraft Server"),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
ServerStatusInfo info = builder.buildInfo(event.getSession());
|
||||
event.getSession().send(new StatusResponsePacket(info));
|
||||
} else if (event.getPacket() instanceof StatusPingPacket) {
|
||||
event.getSession().send(new StatusPongPacket(event.<StatusPingPacket>getPacket().getPingTime()));
|
||||
ServerStatusInfo info = builder.buildInfo(session);
|
||||
session.send(new ClientboundStatusResponsePacket(info));
|
||||
} else if (packet instanceof ServerboundPingRequestPacket) {
|
||||
session.send(new ClientboundPongResponsePacket(((ServerboundPingRequestPacket) packet).getPingTime()));
|
||||
}
|
||||
}
|
||||
|
||||
if (protocol.getSubProtocol() == SubProtocol.GAME) {
|
||||
if (event.getPacket() instanceof ClientKeepAlivePacket) {
|
||||
ClientKeepAlivePacket packet = event.getPacket();
|
||||
if (packet.getPingId() == this.lastPingId) {
|
||||
if (protocol.getState() == ProtocolState.GAME) {
|
||||
if (packet instanceof ServerboundKeepAlivePacket) {
|
||||
if (((ServerboundKeepAlivePacket) packet).getPingId() == this.lastPingId) {
|
||||
long time = System.currentTimeMillis() - this.lastPingTime;
|
||||
event.getSession().setFlag(MinecraftConstants.PING_KEY, time);
|
||||
session.setFlag(MinecraftConstants.PING_KEY, time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetSent(PacketSentEvent event) {
|
||||
Session session = event.getSession();
|
||||
if (event.getPacket() instanceof LoginSetCompressionPacket) {
|
||||
session.setCompressionThreshold(event.<LoginSetCompressionPacket>getPacket().getThreshold());
|
||||
session.send(new LoginSuccessPacket(session.getFlag(MinecraftConstants.PROFILE_KEY)));
|
||||
} else if (event.getPacket() instanceof LoginSuccessPacket) {
|
||||
((MinecraftProtocol) session.getPacketProtocol()).setSubProtocol(SubProtocol.GAME, false, session);
|
||||
public void packetSent(Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundLoginCompressionPacket) {
|
||||
session.setCompressionThreshold(((ClientboundLoginCompressionPacket) packet).getThreshold());
|
||||
session.send(new ClientboundGameProfilePacket((GameProfile) session.getFlag(MinecraftConstants.PROFILE_KEY)));
|
||||
} else if (packet instanceof ClientboundGameProfilePacket) {
|
||||
((MinecraftProtocol) session.getPacketProtocol()).setState(ProtocolState.GAME);
|
||||
ServerLoginHandler handler = session.getFlag(MinecraftConstants.SERVER_LOGIN_HANDLER_KEY);
|
||||
if (handler != null) {
|
||||
handler.loggedIn(session);
|
||||
}
|
||||
|
||||
if (event.getSession().getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
|
||||
if (session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
|
||||
new Thread(new KeepAliveTask(session)).start();
|
||||
}
|
||||
}
|
||||
|
@ -174,10 +171,10 @@ public class ServerListener extends SessionAdapter {
|
|||
@Override
|
||||
public void disconnecting(DisconnectingEvent event) {
|
||||
MinecraftProtocol protocol = (MinecraftProtocol) event.getSession().getPacketProtocol();
|
||||
if (protocol.getSubProtocol() == SubProtocol.LOGIN) {
|
||||
event.getSession().send(new LoginDisconnectPacket(event.getReason()));
|
||||
} else if (protocol.getSubProtocol() == SubProtocol.GAME) {
|
||||
event.getSession().send(new ServerDisconnectPacket(event.getReason()));
|
||||
if (protocol.getState() == ProtocolState.LOGIN) {
|
||||
event.getSession().send(new ClientboundLoginDisconnectPacket(event.getReason()));
|
||||
} else if (protocol.getState() == ProtocolState.GAME) {
|
||||
event.getSession().send(new ClientboundDisconnectPacket(event.getReason()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +189,7 @@ public class ServerListener extends SessionAdapter {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
GameProfile profile = null;
|
||||
GameProfile profile;
|
||||
if (this.key != null) {
|
||||
SessionService sessionService = this.session.getFlag(MinecraftConstants.SESSION_SERVICE_KEY, new SessionService());
|
||||
try {
|
||||
|
@ -212,7 +209,7 @@ public class ServerListener extends SessionAdapter {
|
|||
this.session.setFlag(MinecraftConstants.PROFILE_KEY, profile);
|
||||
|
||||
int threshold = session.getFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD, DEFAULT_COMPRESSION_THRESHOLD);
|
||||
this.session.send(new LoginSetCompressionPacket(threshold));
|
||||
this.session.send(new ClientboundLoginCompressionPacket(threshold));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,7 +225,7 @@ public class ServerListener extends SessionAdapter {
|
|||
while (this.session.isConnected()) {
|
||||
lastPingTime = System.currentTimeMillis();
|
||||
lastPingId = (int) lastPingTime;
|
||||
this.session.send(new ServerKeepAlivePacket(lastPingId));
|
||||
this.session.send(new ClientboundKeepAlivePacket(lastPingId));
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.SubProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@ import com.github.steveice10.packetlib.Session;
|
|||
*/
|
||||
public interface ServerLoginHandler {
|
||||
/**
|
||||
* Called when a session completes the initial login process and is now in the {@link SubProtocol}.GAME.
|
||||
* Called when a session completes the initial login process and is now in the {@link ProtocolState}.GAME.
|
||||
*
|
||||
* @param session Session that logged in.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,301 @@
|
|||
package com.github.steveice10.mc.protocol.codec;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.*;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundAnimatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundMoveEntityPosPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundMoveEntityPosRotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundMoveEntityRotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundMoveVehiclePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundRemoveEntitiesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundRemoveMobEffectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundRotateHeadPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityDataPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityLinkPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityMotionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundSetEquipmentPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundSetPassengersPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundTakeItemEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundTeleportEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundUpdateAttributesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundUpdateMobEffectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundBlockBreakAckPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerAbilitiesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatEndPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatEnterPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatKillPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerLookAtPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundSetCarriedItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundSetExperiencePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundSetHealthPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddExperienceOrbPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddMobPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPaintingPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.*;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.border.ClientboundInitializeBorderPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.border.ClientboundSetBorderCenterPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.border.ClientboundSetBorderLerpSizePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.border.ClientboundSetBorderSizePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.border.ClientboundSetBorderWarningDelayPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.border.ClientboundSetBorderWarningDistancePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.scoreboard.ClientboundSetDisplayObjectivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.scoreboard.ClientboundSetObjectivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.scoreboard.ClientboundSetPlayerTeamPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.scoreboard.ClientboundSetScorePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.title.ClientboundClearTitlesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.title.ClientboundSetActionBarTextPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.title.ClientboundSetSubtitleTextPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.title.ClientboundSetTitleTextPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.title.ClientboundSetTitlesAnimationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundContainerClosePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetContentPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetDataPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetSlotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundHorseScreenOpenPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundMerchantOffersPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundOpenBookPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundOpenScreenPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundPlaceGhostRecipePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChangeDifficultyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientInformationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCommandSuggestionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundKeepAlivePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundLockDifficultyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundPongPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundResourcePackPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundBlockEntityTagQuery;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundEntityTagQuery;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundJigsawGeneratePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundMoveVehiclePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundPaddleBoatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundPlayerInputPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundSignUpdatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundTeleportToEntityPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosRotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerRotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerStatusOnlyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundSetCarriedItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundSwingPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundUseItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClickPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundEditBookPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundPickItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundPlaceRecipePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundRecipeBookChangeSettingsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundRecipeBookSeenRecipePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundRenameItemPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSeenAdvancementsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSelectTradePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetBeaconPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandMinecartPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetJigsawBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetStructureBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundCustomQueryPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundGameProfilePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundHelloPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginCompressionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundLoginDisconnectPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundCustomQueryPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundHelloPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundKeyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundPongResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundStatusResponsePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundPingRequestPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundStatusRequestPacket;
|
||||
|
||||
public class MinecraftCodec {
|
||||
public static final PacketCodec CODEC = PacketCodec.builder()
|
||||
.protocolVersion(757)
|
||||
.minecraftVersion("1.18")
|
||||
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
|
||||
.registerServerboundPacket(0x00, ClientIntentionPacket.class, ClientIntentionPacket::new)
|
||||
)
|
||||
.state(ProtocolState.LOGIN, PacketStateCodec.builder()
|
||||
.registerClientboundPacket(0x00, ClientboundLoginDisconnectPacket.class, ClientboundLoginDisconnectPacket::new)
|
||||
.registerClientboundPacket(0x01, ClientboundHelloPacket.class, ClientboundHelloPacket::new)
|
||||
.registerClientboundPacket(0x02, ClientboundGameProfilePacket.class, ClientboundGameProfilePacket::new)
|
||||
.registerClientboundPacket(0x03, ClientboundLoginCompressionPacket.class, ClientboundLoginCompressionPacket::new)
|
||||
.registerClientboundPacket(0x04, ClientboundCustomQueryPacket.class, ClientboundCustomQueryPacket::new)
|
||||
.registerServerboundPacket(0x00, ServerboundHelloPacket.class, ServerboundHelloPacket::new)
|
||||
.registerServerboundPacket(0x01, ServerboundKeyPacket.class, ServerboundKeyPacket::new)
|
||||
.registerServerboundPacket(0x02, ServerboundCustomQueryPacket.class, ServerboundCustomQueryPacket::new)
|
||||
).state(ProtocolState.STATUS, PacketStateCodec.builder()
|
||||
.registerClientboundPacket(0x00, ClientboundStatusResponsePacket.class, ClientboundStatusResponsePacket::new)
|
||||
.registerClientboundPacket(0x01, ClientboundPongResponsePacket.class, ClientboundPongResponsePacket::new)
|
||||
.registerServerboundPacket(0x00, ServerboundStatusRequestPacket.class, ServerboundStatusRequestPacket::new)
|
||||
.registerServerboundPacket(0x01, ServerboundPingRequestPacket.class, ServerboundPingRequestPacket::new)
|
||||
).state(ProtocolState.GAME, PacketStateCodec.builder()
|
||||
.registerClientboundPacket(0x00, ClientboundAddEntityPacket.class, ClientboundAddEntityPacket::new)
|
||||
.registerClientboundPacket(0x01, ClientboundAddExperienceOrbPacket.class, ClientboundAddExperienceOrbPacket::new)
|
||||
.registerClientboundPacket(0x02, ClientboundAddMobPacket.class, ClientboundAddMobPacket::new)
|
||||
.registerClientboundPacket(0x03, ClientboundAddPaintingPacket.class, ClientboundAddPaintingPacket::new)
|
||||
.registerClientboundPacket(0x04, ClientboundAddPlayerPacket.class, ClientboundAddPlayerPacket::new)
|
||||
.registerClientboundPacket(0x05, ClientboundAddVibrationSignalPacket.class, ClientboundAddVibrationSignalPacket::new)
|
||||
.registerClientboundPacket(0x06, ClientboundAnimatePacket.class, ClientboundAnimatePacket::new)
|
||||
.registerClientboundPacket(0x07, ClientboundAwardStatsPacket.class, ClientboundAwardStatsPacket::new)
|
||||
.registerClientboundPacket(0x08, ClientboundBlockBreakAckPacket.class, ClientboundBlockBreakAckPacket::new)
|
||||
.registerClientboundPacket(0x09, ClientboundBlockDestructionPacket.class, ClientboundBlockDestructionPacket::new)
|
||||
.registerClientboundPacket(0x0A, ClientboundBlockEntityDataPacket.class, ClientboundBlockEntityDataPacket::new)
|
||||
.registerClientboundPacket(0x0B, ClientboundBlockEventPacket.class, ClientboundBlockEventPacket::new)
|
||||
.registerClientboundPacket(0x0C, ClientboundBlockUpdatePacket.class, ClientboundBlockUpdatePacket::new)
|
||||
.registerClientboundPacket(0x0D, ClientboundBossEventPacket.class, ClientboundBossEventPacket::new)
|
||||
.registerClientboundPacket(0x0E, ClientboundChangeDifficultyPacket.class, ClientboundChangeDifficultyPacket::new)
|
||||
.registerClientboundPacket(0x0F, ClientboundChatPacket.class, ClientboundChatPacket::new)
|
||||
.registerClientboundPacket(0x10, ClientboundClearTitlesPacket.class, ClientboundClearTitlesPacket::new)
|
||||
.registerClientboundPacket(0x11, ClientboundCommandSuggestionsPacket.class, ClientboundCommandSuggestionsPacket::new)
|
||||
.registerClientboundPacket(0x12, ClientboundCommandsPacket.class, ClientboundCommandsPacket::new)
|
||||
.registerClientboundPacket(0x13, ClientboundContainerClosePacket.class, ClientboundContainerClosePacket::new)
|
||||
.registerClientboundPacket(0x14, ClientboundContainerSetContentPacket.class, ClientboundContainerSetContentPacket::new)
|
||||
.registerClientboundPacket(0x15, ClientboundContainerSetDataPacket.class, ClientboundContainerSetDataPacket::new)
|
||||
.registerClientboundPacket(0x16, ClientboundContainerSetSlotPacket.class, ClientboundContainerSetSlotPacket::new)
|
||||
.registerClientboundPacket(0x17, ClientboundCooldownPacket.class, ClientboundCooldownPacket::new)
|
||||
.registerClientboundPacket(0x18, ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket::new)
|
||||
.registerClientboundPacket(0x19, ClientboundCustomSoundPacket.class, ClientboundCustomSoundPacket::new)
|
||||
.registerClientboundPacket(0x1A, ClientboundDisconnectPacket.class, ClientboundDisconnectPacket::new)
|
||||
.registerClientboundPacket(0x1B, ClientboundEntityEventPacket.class, ClientboundEntityEventPacket::new)
|
||||
.registerClientboundPacket(0x1C, ClientboundExplodePacket.class, ClientboundExplodePacket::new)
|
||||
.registerClientboundPacket(0x1D, ClientboundForgetLevelChunkPacket.class, ClientboundForgetLevelChunkPacket::new)
|
||||
.registerClientboundPacket(0x1E, ClientboundGameEventPacket.class, ClientboundGameEventPacket::new)
|
||||
.registerClientboundPacket(0x1F, ClientboundHorseScreenOpenPacket.class, ClientboundHorseScreenOpenPacket::new)
|
||||
.registerClientboundPacket(0x20, ClientboundInitializeBorderPacket.class, ClientboundInitializeBorderPacket::new)
|
||||
.registerClientboundPacket(0x21, ClientboundKeepAlivePacket.class, ClientboundKeepAlivePacket::new)
|
||||
.registerClientboundPacket(0x22, ClientboundLevelChunkWithLightPacket.class, ClientboundLevelChunkWithLightPacket::new)
|
||||
.registerClientboundPacket(0x23, ClientboundLevelEventPacket.class, ClientboundLevelEventPacket::new)
|
||||
.registerClientboundPacket(0x24, ClientboundLevelParticlesPacket.class, ClientboundLevelParticlesPacket::new)
|
||||
.registerClientboundPacket(0x25, ClientboundLightUpdatePacket.class, ClientboundLightUpdatePacket::new)
|
||||
.registerClientboundPacket(0x26, ClientboundLoginPacket.class, ClientboundLoginPacket::new)
|
||||
.registerClientboundPacket(0x27, ClientboundMapItemDataPacket.class, ClientboundMapItemDataPacket::new)
|
||||
.registerClientboundPacket(0x28, ClientboundMerchantOffersPacket.class, ClientboundMerchantOffersPacket::new)
|
||||
.registerClientboundPacket(0x29, ClientboundMoveEntityPosPacket.class, ClientboundMoveEntityPosPacket::new)
|
||||
.registerClientboundPacket(0x2A, ClientboundMoveEntityPosRotPacket.class, ClientboundMoveEntityPosRotPacket::new)
|
||||
.registerClientboundPacket(0x2B, ClientboundMoveEntityRotPacket.class, ClientboundMoveEntityRotPacket::new)
|
||||
.registerClientboundPacket(0x2C, ClientboundMoveVehiclePacket.class, ClientboundMoveVehiclePacket::new)
|
||||
.registerClientboundPacket(0x2D, ClientboundOpenBookPacket.class, ClientboundOpenBookPacket::new)
|
||||
.registerClientboundPacket(0x2E, ClientboundOpenScreenPacket.class, ClientboundOpenScreenPacket::new)
|
||||
.registerClientboundPacket(0x2F, ClientboundOpenSignEditorPacket.class, ClientboundOpenSignEditorPacket::new)
|
||||
.registerClientboundPacket(0x30, ClientboundPingPacket.class, ClientboundPingPacket::new)
|
||||
.registerClientboundPacket(0x31, ClientboundPlaceGhostRecipePacket.class, ClientboundPlaceGhostRecipePacket::new)
|
||||
.registerClientboundPacket(0x32, ClientboundPlayerAbilitiesPacket.class, ClientboundPlayerAbilitiesPacket::new)
|
||||
.registerClientboundPacket(0x33, ClientboundPlayerCombatEndPacket.class, ClientboundPlayerCombatEndPacket::new)
|
||||
.registerClientboundPacket(0x34, ClientboundPlayerCombatEnterPacket.class, ClientboundPlayerCombatEnterPacket::new)
|
||||
.registerClientboundPacket(0x35, ClientboundPlayerCombatKillPacket.class, ClientboundPlayerCombatKillPacket::new)
|
||||
.registerClientboundPacket(0x36, ClientboundPlayerInfoPacket.class, ClientboundPlayerInfoPacket::new)
|
||||
.registerClientboundPacket(0x37, ClientboundPlayerLookAtPacket.class, ClientboundPlayerLookAtPacket::new)
|
||||
.registerClientboundPacket(0x38, ClientboundPlayerPositionPacket.class, ClientboundPlayerPositionPacket::new)
|
||||
.registerClientboundPacket(0x39, ClientboundRecipePacket.class, ClientboundRecipePacket::new)
|
||||
.registerClientboundPacket(0x3A, ClientboundRemoveEntitiesPacket.class, ClientboundRemoveEntitiesPacket::new)
|
||||
.registerClientboundPacket(0x3B, ClientboundRemoveMobEffectPacket.class, ClientboundRemoveMobEffectPacket::new)
|
||||
.registerClientboundPacket(0x3C, ClientboundResourcePackPacket.class, ClientboundResourcePackPacket::new)
|
||||
.registerClientboundPacket(0x3D, ClientboundRespawnPacket.class, ClientboundRespawnPacket::new)
|
||||
.registerClientboundPacket(0x3E, ClientboundRotateHeadPacket.class, ClientboundRotateHeadPacket::new)
|
||||
.registerClientboundPacket(0x3F, ClientboundSectionBlocksUpdatePacket.class, ClientboundSectionBlocksUpdatePacket::new)
|
||||
.registerClientboundPacket(0x40, ClientboundSelectAdvancementsTabPacket.class, ClientboundSelectAdvancementsTabPacket::new)
|
||||
.registerClientboundPacket(0x41, ClientboundSetActionBarTextPacket.class, ClientboundSetActionBarTextPacket::new)
|
||||
.registerClientboundPacket(0x42, ClientboundSetBorderCenterPacket.class, ClientboundSetBorderCenterPacket::new)
|
||||
.registerClientboundPacket(0x43, ClientboundSetBorderLerpSizePacket.class, ClientboundSetBorderLerpSizePacket::new)
|
||||
.registerClientboundPacket(0x44, ClientboundSetBorderSizePacket.class, ClientboundSetBorderSizePacket::new)
|
||||
.registerClientboundPacket(0x45, ClientboundSetBorderWarningDelayPacket.class, ClientboundSetBorderWarningDelayPacket::new)
|
||||
.registerClientboundPacket(0x46, ClientboundSetBorderWarningDistancePacket.class, ClientboundSetBorderWarningDistancePacket::new)
|
||||
.registerClientboundPacket(0x47, ClientboundSetCameraPacket.class, ClientboundSetCameraPacket::new)
|
||||
.registerClientboundPacket(0x48, ClientboundSetCarriedItemPacket.class, ClientboundSetCarriedItemPacket::new)
|
||||
.registerClientboundPacket(0x49, ClientboundSetChunkCacheCenterPacket.class, ClientboundSetChunkCacheCenterPacket::new)
|
||||
.registerClientboundPacket(0x4A, ClientboundSetChunkCacheRadiusPacket.class, ClientboundSetChunkCacheRadiusPacket::new)
|
||||
.registerClientboundPacket(0x4B, ClientboundSetDefaultSpawnPositionPacket.class, ClientboundSetDefaultSpawnPositionPacket::new)
|
||||
.registerClientboundPacket(0x4C, ClientboundSetDisplayObjectivePacket.class, ClientboundSetDisplayObjectivePacket::new)
|
||||
.registerClientboundPacket(0x4D, ClientboundSetEntityDataPacket.class, ClientboundSetEntityDataPacket::new)
|
||||
.registerClientboundPacket(0x4E, ClientboundSetEntityLinkPacket.class, ClientboundSetEntityLinkPacket::new)
|
||||
.registerClientboundPacket(0x4F, ClientboundSetEntityMotionPacket.class, ClientboundSetEntityMotionPacket::new)
|
||||
.registerClientboundPacket(0x50, ClientboundSetEquipmentPacket.class, ClientboundSetEquipmentPacket::new)
|
||||
.registerClientboundPacket(0x51, ClientboundSetExperiencePacket.class, ClientboundSetExperiencePacket::new)
|
||||
.registerClientboundPacket(0x52, ClientboundSetHealthPacket.class, ClientboundSetHealthPacket::new)
|
||||
.registerClientboundPacket(0x53, ClientboundSetObjectivePacket.class, ClientboundSetObjectivePacket::new)
|
||||
.registerClientboundPacket(0x54, ClientboundSetPassengersPacket.class, ClientboundSetPassengersPacket::new)
|
||||
.registerClientboundPacket(0x55, ClientboundSetPlayerTeamPacket.class, ClientboundSetPlayerTeamPacket::new)
|
||||
.registerClientboundPacket(0x56, ClientboundSetScorePacket.class, ClientboundSetScorePacket::new)
|
||||
.registerClientboundPacket(0x57, ClientboundSetSimulationDistancePacket.class, ClientboundSetSimulationDistancePacket::new)
|
||||
.registerClientboundPacket(0x58, ClientboundSetSubtitleTextPacket.class, ClientboundSetSubtitleTextPacket::new)
|
||||
.registerClientboundPacket(0x59, ClientboundSetTimePacket.class, ClientboundSetTimePacket::new)
|
||||
.registerClientboundPacket(0x5A, ClientboundSetTitleTextPacket.class, ClientboundSetTitleTextPacket::new)
|
||||
.registerClientboundPacket(0x5B, ClientboundSetTitlesAnimationPacket.class, ClientboundSetTitlesAnimationPacket::new)
|
||||
.registerClientboundPacket(0x5C, ClientboundSoundEntityPacket.class, ClientboundSoundEntityPacket::new)
|
||||
.registerClientboundPacket(0x5D, ClientboundSoundPacket.class, ClientboundSoundPacket::new)
|
||||
.registerClientboundPacket(0x5E, ClientboundStopSoundPacket.class, ClientboundStopSoundPacket::new)
|
||||
.registerClientboundPacket(0x5F, ClientboundTabListPacket.class, ClientboundTabListPacket::new)
|
||||
.registerClientboundPacket(0x60, ClientboundTagQueryPacket.class, ClientboundTagQueryPacket::new)
|
||||
.registerClientboundPacket(0x61, ClientboundTakeItemEntityPacket.class, ClientboundTakeItemEntityPacket::new)
|
||||
.registerClientboundPacket(0x62, ClientboundTeleportEntityPacket.class, ClientboundTeleportEntityPacket::new)
|
||||
.registerClientboundPacket(0x63, ClientboundUpdateAdvancementsPacket.class, ClientboundUpdateAdvancementsPacket::new)
|
||||
.registerClientboundPacket(0x64, ClientboundUpdateAttributesPacket.class, ClientboundUpdateAttributesPacket::new)
|
||||
.registerClientboundPacket(0x65, ClientboundUpdateMobEffectPacket.class, ClientboundUpdateMobEffectPacket::new)
|
||||
.registerClientboundPacket(0x66, ClientboundUpdateRecipesPacket.class, ClientboundUpdateRecipesPacket::new)
|
||||
.registerClientboundPacket(0x67, ClientboundUpdateTagsPacket.class, ClientboundUpdateTagsPacket::new)
|
||||
.registerServerboundPacket(0x00, ServerboundAcceptTeleportationPacket.class, ServerboundAcceptTeleportationPacket::new)
|
||||
.registerServerboundPacket(0x01, ServerboundBlockEntityTagQuery.class, ServerboundBlockEntityTagQuery::new)
|
||||
.registerServerboundPacket(0x02, ServerboundChangeDifficultyPacket.class, ServerboundChangeDifficultyPacket::new)
|
||||
.registerServerboundPacket(0x03, ServerboundChatPacket.class, ServerboundChatPacket::new)
|
||||
.registerServerboundPacket(0x04, ServerboundClientCommandPacket.class, ServerboundClientCommandPacket::new)
|
||||
.registerServerboundPacket(0x05, ServerboundClientInformationPacket.class, ServerboundClientInformationPacket::new)
|
||||
.registerServerboundPacket(0x06, ServerboundCommandSuggestionPacket.class, ServerboundCommandSuggestionPacket::new)
|
||||
.registerServerboundPacket(0x07, ServerboundContainerButtonClickPacket.class, ServerboundContainerButtonClickPacket::new)
|
||||
.registerServerboundPacket(0x08, ServerboundContainerClickPacket.class, ServerboundContainerClickPacket::new)
|
||||
.registerServerboundPacket(0x09, ServerboundContainerClosePacket.class, ServerboundContainerClosePacket::new)
|
||||
.registerServerboundPacket(0x0A, ServerboundCustomPayloadPacket.class, ServerboundCustomPayloadPacket::new)
|
||||
.registerServerboundPacket(0x0B, ServerboundEditBookPacket.class, ServerboundEditBookPacket::new)
|
||||
.registerServerboundPacket(0x0C, ServerboundEntityTagQuery.class, ServerboundEntityTagQuery::new)
|
||||
.registerServerboundPacket(0x0D, ServerboundInteractPacket.class, ServerboundInteractPacket::new)
|
||||
.registerServerboundPacket(0x0E, ServerboundJigsawGeneratePacket.class, ServerboundJigsawGeneratePacket::new)
|
||||
.registerServerboundPacket(0x0F, ServerboundKeepAlivePacket.class, ServerboundKeepAlivePacket::new)
|
||||
.registerServerboundPacket(0x10, ServerboundLockDifficultyPacket.class, ServerboundLockDifficultyPacket::new)
|
||||
.registerServerboundPacket(0x11, ServerboundMovePlayerPosPacket.class, ServerboundMovePlayerPosPacket::new)
|
||||
.registerServerboundPacket(0x12, ServerboundMovePlayerPosRotPacket.class, ServerboundMovePlayerPosRotPacket::new)
|
||||
.registerServerboundPacket(0x13, ServerboundMovePlayerRotPacket.class, ServerboundMovePlayerRotPacket::new)
|
||||
.registerServerboundPacket(0x14, ServerboundMovePlayerStatusOnlyPacket.class, ServerboundMovePlayerStatusOnlyPacket::new)
|
||||
.registerServerboundPacket(0x15, ServerboundMoveVehiclePacket.class, ServerboundMoveVehiclePacket::new)
|
||||
.registerServerboundPacket(0x16, ServerboundPaddleBoatPacket.class, ServerboundPaddleBoatPacket::new)
|
||||
.registerServerboundPacket(0x17, ServerboundPickItemPacket.class, ServerboundPickItemPacket::new)
|
||||
.registerServerboundPacket(0x18, ServerboundPlaceRecipePacket.class, ServerboundPlaceRecipePacket::new)
|
||||
.registerServerboundPacket(0x19, ServerboundPlayerAbilitiesPacket.class, ServerboundPlayerAbilitiesPacket::new)
|
||||
.registerServerboundPacket(0x1A, ServerboundPlayerActionPacket.class, ServerboundPlayerActionPacket::new)
|
||||
.registerServerboundPacket(0x1B, ServerboundPlayerCommandPacket.class, ServerboundPlayerCommandPacket::new)
|
||||
.registerServerboundPacket(0x1C, ServerboundPlayerInputPacket.class, ServerboundPlayerInputPacket::new)
|
||||
.registerServerboundPacket(0x1D, ServerboundPongPacket.class, ServerboundPongPacket::new)
|
||||
.registerServerboundPacket(0x1E, ServerboundRecipeBookChangeSettingsPacket.class, ServerboundRecipeBookChangeSettingsPacket::new)
|
||||
.registerServerboundPacket(0x1F, ServerboundRecipeBookSeenRecipePacket.class, ServerboundRecipeBookSeenRecipePacket::new)
|
||||
.registerServerboundPacket(0x20, ServerboundRenameItemPacket.class, ServerboundRenameItemPacket::new)
|
||||
.registerServerboundPacket(0x21, ServerboundResourcePackPacket.class, ServerboundResourcePackPacket::new)
|
||||
.registerServerboundPacket(0x22, ServerboundSeenAdvancementsPacket.class, ServerboundSeenAdvancementsPacket::new)
|
||||
.registerServerboundPacket(0x23, ServerboundSelectTradePacket.class, ServerboundSelectTradePacket::new)
|
||||
.registerServerboundPacket(0x24, ServerboundSetBeaconPacket.class, ServerboundSetBeaconPacket::new)
|
||||
.registerServerboundPacket(0x25, ServerboundSetCarriedItemPacket.class, ServerboundSetCarriedItemPacket::new)
|
||||
.registerServerboundPacket(0x26, ServerboundSetCommandBlockPacket.class, ServerboundSetCommandBlockPacket::new)
|
||||
.registerServerboundPacket(0x27, ServerboundSetCommandMinecartPacket.class, ServerboundSetCommandMinecartPacket::new)
|
||||
.registerServerboundPacket(0x28, ServerboundSetCreativeModeSlotPacket.class, ServerboundSetCreativeModeSlotPacket::new)
|
||||
.registerServerboundPacket(0x29, ServerboundSetJigsawBlockPacket.class, ServerboundSetJigsawBlockPacket::new)
|
||||
.registerServerboundPacket(0x2A, ServerboundSetStructureBlockPacket.class, ServerboundSetStructureBlockPacket::new)
|
||||
.registerServerboundPacket(0x2B, ServerboundSignUpdatePacket.class, ServerboundSignUpdatePacket::new)
|
||||
.registerServerboundPacket(0x2C, ServerboundSwingPacket.class, ServerboundSwingPacket::new)
|
||||
.registerServerboundPacket(0x2D, ServerboundTeleportToEntityPacket.class, ServerboundTeleportToEntityPacket::new)
|
||||
.registerServerboundPacket(0x2E, ServerboundUseItemOnPacket.class, ServerboundUseItemOnPacket::new)
|
||||
.registerServerboundPacket(0x2F, ServerboundUseItemPacket.class, ServerboundUseItemPacket::new)
|
||||
)
|
||||
.build();
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.github.steveice10.mc.protocol.codec;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.util.EnumMap;
|
||||
|
||||
@Immutable
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class PacketCodec {
|
||||
|
||||
@Getter
|
||||
private final int protocolVersion;
|
||||
|
||||
@Getter
|
||||
private final String minecraftVersion;
|
||||
|
||||
private final EnumMap<ProtocolState, PacketStateCodec> stateProtocols;
|
||||
|
||||
public PacketStateCodec getCodec(ProtocolState protocolState) {
|
||||
return this.stateProtocols.get(protocolState);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
Builder builder = new Builder();
|
||||
|
||||
builder.protocolVersion = this.protocolVersion;
|
||||
builder.stateProtocols = this.stateProtocols;
|
||||
builder.minecraftVersion = this.minecraftVersion;
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private int protocolVersion = -1;
|
||||
private String minecraftVersion = null;
|
||||
private EnumMap<ProtocolState, PacketStateCodec> stateProtocols = new EnumMap<>(ProtocolState.class);
|
||||
|
||||
public Builder protocolVersion(int protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder minecraftVersion(String minecraftVersion) {
|
||||
this.minecraftVersion = minecraftVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(ProtocolState state, PacketStateCodec.Builder protocol) {
|
||||
this.stateProtocols.put(state, protocol.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketCodec build() {
|
||||
return new PacketCodec(this.protocolVersion, this.minecraftVersion, this.stateProtocols);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.github.steveice10.mc.protocol.codec;
|
||||
|
||||
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
||||
import com.github.steveice10.packetlib.Server;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.crypt.PacketEncryption;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.packet.PacketDefinition;
|
||||
import com.github.steveice10.packetlib.packet.PacketFactory;
|
||||
import com.github.steveice10.packetlib.packet.PacketHeader;
|
||||
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PacketStateCodec extends PacketProtocol {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSRVRecordPrefix() {
|
||||
return MinecraftConstants.SRV_RECORD_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketHeader getPacketHeader() {
|
||||
return MinecraftConstants.PACKET_HEADER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newClientSession(Session session) {
|
||||
throw new UnsupportedOperationException("Not supported!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newServerSession(Server server, Session session) {
|
||||
throw new UnsupportedOperationException("Not supported!");
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final Map<Integer, PacketDefinition<? extends Packet>> clientboundPackets = new HashMap<>();
|
||||
private final Map<Integer, PacketDefinition<? extends Packet>> serverboundPackets = new HashMap<>();
|
||||
|
||||
public <T extends Packet> Builder registerClientboundPacket(int id, Class<T> packetClass, PacketFactory<T> factory) {
|
||||
this.clientboundPackets.put(id, new PacketDefinition<>(id, packetClass, factory));
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends Packet> Builder registerServerboundPacket(int id, Class<T> packetClass, PacketFactory<T> factory) {
|
||||
this.serverboundPackets.put(id, new PacketDefinition<>(id, packetClass, factory));
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketStateCodec build() {
|
||||
PacketStateCodec codec = new PacketStateCodec();
|
||||
for (Map.Entry<Integer, PacketDefinition<? extends Packet>> entry : this.clientboundPackets.entrySet()) {
|
||||
codec.registerClientbound(entry.getValue());
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, PacketDefinition<? extends Packet>> entry : this.serverboundPackets.entrySet()) {
|
||||
codec.registerServerbound(entry.getValue());
|
||||
}
|
||||
|
||||
return codec;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ package com.github.steveice10.mc.protocol.data;
|
|||
import com.github.steveice10.mc.protocol.data.game.BossBarAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.BossBarColor;
|
||||
import com.github.steveice10.mc.protocol.data.game.BossBarDivision;
|
||||
import com.github.steveice10.mc.protocol.data.game.ClientRequest;
|
||||
import com.github.steveice10.mc.protocol.data.game.ClientCommand;
|
||||
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
||||
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.ResourcePackStatus;
|
||||
|
@ -13,18 +13,11 @@ import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
|
|||
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.SuggestionType;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.properties.StringProperties;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EntityStatus;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.RotationOrigin;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierOperation;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.object.HangingDirection;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.object.MinecartType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.BlockBreakStage;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.HandPreference;
|
||||
|
@ -32,9 +25,28 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
|
|||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PositionElement;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.type.WeatherEntityType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.StructureMirror;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.StructureRotation;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.value.ChestValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.value.EndGatewayValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.value.GenericBlockValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.value.MobSpawnerValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.value.NoteBlockValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.event.ComposterEventData;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.event.DragonFireballEventData;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.event.ParticleEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.event.SmokeEventData;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.map.MapIconType;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.DemoMessageValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.EnterCreditsValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.RespawnScreenValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility;
|
||||
|
@ -43,143 +55,43 @@ import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreType;
|
|||
import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardPosition;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
||||
import com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility;
|
||||
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
||||
import com.github.steveice10.mc.protocol.data.game.statistic.GenericStatistic;
|
||||
import com.github.steveice10.mc.protocol.data.game.statistic.StatisticCategory;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.AdvancementTabAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.ClickItemParam;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.CraftingBookStateType;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.CreativeGrabParam;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.DropItemParam;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.FillStackParam;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.MoveToHotbarParam;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.ShiftClickItemParam;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.SpreadItemParam;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.UpdateStructureBlockAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.UpdateStructureBlockMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.WindowAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.property.AnvilProperty;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.property.BrewingStandProperty;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.property.EnchantmentTableProperty;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.property.FurnaceProperty;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.CommandBlockMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.StructureMirror;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.StructureRotation;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.UpdatedTileType;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.value.ChestValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.value.EndGatewayValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.value.GenericBlockValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.value.MobSpawnerValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.value.NoteBlockValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.value.PistonValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.value.PistonValueType;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.effect.ComposterEffectData;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.effect.DragonFireballEffectData;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.effect.ParticleEffect;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.effect.SmokeEffectData;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.effect.SoundEffect;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.map.MapIconType;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.notify.ClientNotification;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.notify.DemoMessageValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.notify.EnterCreditsValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.notify.RespawnScreenValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.sound.SoundCategory;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.AdvancementTabAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.ClickItemAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.CraftingBookStateType;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.CreativeGrabAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.DropItemAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.FillStackAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.MoveToHotbarAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.ShiftClickItemAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.SpreadItemAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.UpdateStructureBlockAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.UpdateStructureBlockMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.ContainerActionType;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.property.AnvilProperty;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.property.BrewingStandProperty;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.property.EnchantmentTableProperty;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.property.FurnaceProperty;
|
||||
import com.github.steveice10.mc.protocol.data.handshake.HandshakeIntent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MagicValues {
|
||||
private static final Map<Object, List<Object>> VALUES = new HashMap<>();
|
||||
|
||||
static {
|
||||
register(Pose.STANDING, 0);
|
||||
register(Pose.FALL_FLYING, 1);
|
||||
register(Pose.SLEEPING, 2);
|
||||
register(Pose.SWIMMING, 3);
|
||||
register(Pose.SPIN_ATTACK, 4);
|
||||
register(Pose.SNEAKING, 5);
|
||||
register(Pose.LONG_JUMPING, 6);
|
||||
register(Pose.DYING, 7);
|
||||
|
||||
register(AttributeType.GENERIC_MAX_HEALTH, "minecraft:generic.max_health");
|
||||
register(AttributeType.GENERIC_FOLLOW_RANGE, "minecraft:generic.follow_range");
|
||||
register(AttributeType.GENERIC_KNOCKBACK_RESISTANCE, "minecraft:generic.knockback_resistance");
|
||||
register(AttributeType.GENERIC_MOVEMENT_SPEED, "minecraft:generic.movement_speed");
|
||||
register(AttributeType.GENERIC_ATTACK_DAMAGE, "minecraft:generic.attack_damage");
|
||||
register(AttributeType.GENERIC_ATTACK_KNOCKBACK, "minecraft:generic.attack_knockback");
|
||||
register(AttributeType.GENERIC_ATTACK_SPEED, "minecraft:generic.attack_speed");
|
||||
register(AttributeType.GENERIC_ARMOR, "minecraft:generic.armor");
|
||||
register(AttributeType.GENERIC_ARMOR_TOUGHNESS, "minecraft:generic.armor_toughness");
|
||||
register(AttributeType.GENERIC_LUCK, "minecraft:generic.luck");
|
||||
register(AttributeType.GENERIC_FLYING_SPEED, "minecraft:generic.flying_speed");
|
||||
register(AttributeType.HORSE_JUMP_STRENGTH, "minecraft:horse.jump_strength");
|
||||
register(AttributeType.ZOMBIE_SPAWN_REINFORCEMENTS, "minecraft:zombie.spawn_reinforcements");
|
||||
// Forge-only
|
||||
register(AttributeType.ENTITY_GRAVITY, "forge:entity_gravity");
|
||||
|
||||
register(ModifierType.CREATURE_FLEE_SPEED_BONUS, UUID.fromString("E199AD21-BA8A-4C53-8D13-6182D5C69D3A"));
|
||||
register(ModifierType.ENDERMAN_ATTACK_SPEED_BOOST, UUID.fromString("020E0DFB-87AE-4653-9556-831010E291A0"));
|
||||
register(ModifierType.SPRINT_SPEED_BOOST, UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D"));
|
||||
register(ModifierType.PIGZOMBIE_ATTACK_SPEED_BOOST, UUID.fromString("49455A49-7EC5-45BA-B886-3B90B23A1718"));
|
||||
register(ModifierType.WITCH_DRINKING_SPEED_PENALTY, UUID.fromString("5CD17E52-A79A-43D3-A529-90FDE04B181E"));
|
||||
register(ModifierType.ZOMBIE_BABY_SPEED_BOOST, UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836"));
|
||||
register(ModifierType.ATTACK_DAMAGE_MODIFIER, UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"));
|
||||
register(ModifierType.ATTACK_SPEED_MODIFIER, UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"));
|
||||
register(ModifierType.SPEED_POTION_MODIFIER, UUID.fromString("91AEAA56-376B-4498-935B-2F7F68070635"));
|
||||
register(ModifierType.HEALTH_BOOST_POTION_MODIFIER, UUID.fromString("5D6F0BA2-1186-46AC-B896-C61C5CEE99CC"));
|
||||
register(ModifierType.SLOW_POTION_MODIFIER, UUID.fromString("7107DE5E-7CE8-4030-940E-514C1F160890"));
|
||||
register(ModifierType.STRENGTH_POTION_MODIFIER, UUID.fromString("648D7064-6A60-4F59-8ABE-C2C23A6DD7A9"));
|
||||
register(ModifierType.WEAKNESS_POTION_MODIFIER, UUID.fromString("22653B89-116E-49DC-9B6B-9971489B5BE5"));
|
||||
register(ModifierType.HASTE_POTION_MODIFIER, UUID.fromString("AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3"));
|
||||
register(ModifierType.MINING_FATIGUE_POTION_MODIFIER, UUID.fromString("55FCED67-E92A-486E-9800-B47F202C4386"));
|
||||
register(ModifierType.LUCK_POTION_MODIFIER, UUID.fromString("03C3C89D-7037-4B42-869F-B146BCB64D2E"));
|
||||
register(ModifierType.UNLUCK_POTION_MODIFIER, UUID.fromString("CC5AF142-2BD2-4215-B636-2605AED11727"));
|
||||
register(ModifierType.BOOTS_MODIFIER, UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"));
|
||||
register(ModifierType.LEGGINGS_MODIFIER, UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"));
|
||||
register(ModifierType.CHESTPLATE_MODIFIER, UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"));
|
||||
register(ModifierType.HELMET_MODIFIER, UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150"));
|
||||
register(ModifierType.COVERED_ARMOR_BONUS, UUID.fromString("7E0292F2-9434-48D5-A29F-9583AF7DF27F"));
|
||||
// Forge-only
|
||||
register(ModifierType.SLOW_FALLING, UUID.fromString("A5B6CF2A-2F7C-31EF-9022-7C3E7D5E6ABA"));
|
||||
|
||||
register(ModifierOperation.ADD, 0);
|
||||
register(ModifierOperation.ADD_MULTIPLIED, 1);
|
||||
register(ModifierOperation.MULTIPLY, 2);
|
||||
|
||||
register(MetadataType.BYTE, 0);
|
||||
register(MetadataType.INT, 1);
|
||||
register(MetadataType.FLOAT, 2);
|
||||
register(MetadataType.STRING, 3);
|
||||
register(MetadataType.CHAT, 4);
|
||||
register(MetadataType.OPTIONAL_CHAT, 5);
|
||||
register(MetadataType.ITEM, 6);
|
||||
register(MetadataType.BOOLEAN, 7);
|
||||
register(MetadataType.ROTATION, 8);
|
||||
register(MetadataType.POSITION, 9);
|
||||
register(MetadataType.OPTIONAL_POSITION, 10);
|
||||
register(MetadataType.BLOCK_FACE, 11);
|
||||
register(MetadataType.OPTIONAL_UUID, 12);
|
||||
register(MetadataType.BLOCK_STATE, 13);
|
||||
register(MetadataType.NBT_TAG, 14);
|
||||
register(MetadataType.PARTICLE, 15);
|
||||
register(MetadataType.VILLAGER_DATA, 16);
|
||||
register(MetadataType.OPTIONAL_VARINT, 17);
|
||||
register(MetadataType.POSE, 18);
|
||||
|
||||
register(HandshakeIntent.STATUS, 1);
|
||||
register(HandshakeIntent.LOGIN, 2);
|
||||
|
||||
register(ClientRequest.RESPAWN, 0);
|
||||
register(ClientRequest.STATS, 1);
|
||||
register(ClientCommand.RESPAWN, 0);
|
||||
register(ClientCommand.STATS, 1);
|
||||
|
||||
register(ChatVisibility.FULL, 0);
|
||||
register(ChatVisibility.SYSTEM, 1);
|
||||
|
@ -207,48 +119,48 @@ public class MagicValues {
|
|||
register(PlayerAction.RELEASE_USE_ITEM, 5);
|
||||
register(PlayerAction.SWAP_HANDS, 6);
|
||||
|
||||
register(WindowAction.CLICK_ITEM, 0);
|
||||
register(WindowAction.SHIFT_CLICK_ITEM, 1);
|
||||
register(WindowAction.MOVE_TO_HOTBAR_SLOT, 2);
|
||||
register(WindowAction.CREATIVE_GRAB_MAX_STACK, 3);
|
||||
register(WindowAction.DROP_ITEM, 4);
|
||||
register(WindowAction.SPREAD_ITEM, 5);
|
||||
register(WindowAction.FILL_STACK, 6);
|
||||
register(ContainerActionType.CLICK_ITEM, 0);
|
||||
register(ContainerActionType.SHIFT_CLICK_ITEM, 1);
|
||||
register(ContainerActionType.MOVE_TO_HOTBAR_SLOT, 2);
|
||||
register(ContainerActionType.CREATIVE_GRAB_MAX_STACK, 3);
|
||||
register(ContainerActionType.DROP_ITEM, 4);
|
||||
register(ContainerActionType.SPREAD_ITEM, 5);
|
||||
register(ContainerActionType.FILL_STACK, 6);
|
||||
|
||||
register(ClickItemParam.LEFT_CLICK, 0);
|
||||
register(ClickItemParam.RIGHT_CLICK, 1);
|
||||
register(ClickItemAction.LEFT_CLICK, 0);
|
||||
register(ClickItemAction.RIGHT_CLICK, 1);
|
||||
|
||||
register(ShiftClickItemParam.LEFT_CLICK, 0);
|
||||
register(ShiftClickItemParam.RIGHT_CLICK, 1);
|
||||
register(ShiftClickItemAction.LEFT_CLICK, 0);
|
||||
register(ShiftClickItemAction.RIGHT_CLICK, 1);
|
||||
|
||||
register(MoveToHotbarParam.SLOT_1, 0);
|
||||
register(MoveToHotbarParam.SLOT_2, 1);
|
||||
register(MoveToHotbarParam.SLOT_3, 2);
|
||||
register(MoveToHotbarParam.SLOT_4, 3);
|
||||
register(MoveToHotbarParam.SLOT_5, 4);
|
||||
register(MoveToHotbarParam.SLOT_6, 5);
|
||||
register(MoveToHotbarParam.SLOT_7, 6);
|
||||
register(MoveToHotbarParam.SLOT_8, 7);
|
||||
register(MoveToHotbarParam.SLOT_9, 8);
|
||||
register(MoveToHotbarAction.SLOT_1, 0);
|
||||
register(MoveToHotbarAction.SLOT_2, 1);
|
||||
register(MoveToHotbarAction.SLOT_3, 2);
|
||||
register(MoveToHotbarAction.SLOT_4, 3);
|
||||
register(MoveToHotbarAction.SLOT_5, 4);
|
||||
register(MoveToHotbarAction.SLOT_6, 5);
|
||||
register(MoveToHotbarAction.SLOT_7, 6);
|
||||
register(MoveToHotbarAction.SLOT_8, 7);
|
||||
register(MoveToHotbarAction.SLOT_9, 8);
|
||||
|
||||
register(CreativeGrabParam.GRAB, 2);
|
||||
register(CreativeGrabAction.GRAB, 2);
|
||||
|
||||
register(DropItemParam.LEFT_CLICK_OUTSIDE_NOT_HOLDING, 0);
|
||||
register(DropItemParam.RIGHT_CLICK_OUTSIDE_NOT_HOLDING, 1);
|
||||
register(DropItemParam.DROP_FROM_SELECTED, 2);
|
||||
register(DropItemParam.DROP_SELECTED_STACK, 3);
|
||||
register(DropItemAction.LEFT_CLICK_OUTSIDE_NOT_HOLDING, 0);
|
||||
register(DropItemAction.RIGHT_CLICK_OUTSIDE_NOT_HOLDING, 1);
|
||||
register(DropItemAction.DROP_FROM_SELECTED, 2);
|
||||
register(DropItemAction.DROP_SELECTED_STACK, 3);
|
||||
|
||||
register(SpreadItemParam.LEFT_MOUSE_BEGIN_DRAG, 0);
|
||||
register(SpreadItemParam.LEFT_MOUSE_ADD_SLOT, 1);
|
||||
register(SpreadItemParam.LEFT_MOUSE_END_DRAG, 2);
|
||||
register(SpreadItemParam.RIGHT_MOUSE_BEGIN_DRAG, 4);
|
||||
register(SpreadItemParam.RIGHT_MOUSE_ADD_SLOT, 5);
|
||||
register(SpreadItemParam.RIGHT_MOUSE_END_DRAG, 6);
|
||||
register(SpreadItemParam.MIDDLE_MOUSE_BEGIN_DRAG, 8);
|
||||
register(SpreadItemParam.MIDDLE_MOUSE_ADD_SLOT, 9);
|
||||
register(SpreadItemParam.MIDDLE_MOUSE_END_DRAG, 10);
|
||||
register(SpreadItemAction.LEFT_MOUSE_BEGIN_DRAG, 0);
|
||||
register(SpreadItemAction.LEFT_MOUSE_ADD_SLOT, 1);
|
||||
register(SpreadItemAction.LEFT_MOUSE_END_DRAG, 2);
|
||||
register(SpreadItemAction.RIGHT_MOUSE_BEGIN_DRAG, 4);
|
||||
register(SpreadItemAction.RIGHT_MOUSE_ADD_SLOT, 5);
|
||||
register(SpreadItemAction.RIGHT_MOUSE_END_DRAG, 6);
|
||||
register(SpreadItemAction.MIDDLE_MOUSE_BEGIN_DRAG, 8);
|
||||
register(SpreadItemAction.MIDDLE_MOUSE_ADD_SLOT, 9);
|
||||
register(SpreadItemAction.MIDDLE_MOUSE_END_DRAG, 10);
|
||||
|
||||
register(FillStackParam.FILL, 0);
|
||||
register(FillStackAction.FILL, 0);
|
||||
|
||||
register(MessageType.CHAT, 0);
|
||||
register(MessageType.SYSTEM, 1);
|
||||
|
@ -268,70 +180,70 @@ public class MagicValues {
|
|||
register(Animation.SWING_ARM, 0);
|
||||
register(Animation.DAMAGE, 1);
|
||||
register(Animation.LEAVE_BED, 2);
|
||||
register(Animation.EAT_FOOD, 3);
|
||||
register(Animation.SWING_OFFHAND, 3);
|
||||
register(Animation.CRITICAL_HIT, 4);
|
||||
register(Animation.ENCHANTMENT_CRITICAL_HIT, 5);
|
||||
|
||||
register(EntityStatus.TIPPED_ARROW_EMIT_PARTICLES, 0);
|
||||
register(EntityStatus.RABBIT_JUMP_OR_MINECART_SPAWNER_DELAY_RESET, 1);
|
||||
register(EntityStatus.LIVING_HURT, 2);
|
||||
register(EntityStatus.LIVING_DEATH, 3);
|
||||
register(EntityStatus.IRON_GOLEM_ATTACK, 4);
|
||||
register(EntityStatus.TAMEABLE_TAMING_FAILED, 6);
|
||||
register(EntityStatus.TAMEABLE_TAMING_SUCCEEDED, 7);
|
||||
register(EntityStatus.WOLF_SHAKE_WATER, 8);
|
||||
register(EntityStatus.PLAYER_FINISH_USING_ITEM, 9);
|
||||
register(EntityStatus.SHEEP_GRAZE_OR_TNT_CART_EXPLODE, 10);
|
||||
register(EntityStatus.IRON_GOLEM_HOLD_POPPY, 11);
|
||||
register(EntityStatus.VILLAGER_MATE, 12);
|
||||
register(EntityStatus.VILLAGER_ANGRY, 13);
|
||||
register(EntityStatus.VILLAGER_HAPPY, 14);
|
||||
register(EntityStatus.WITCH_EMIT_PARTICLES, 15);
|
||||
register(EntityStatus.ZOMBIE_VILLAGER_CURE, 16);
|
||||
register(EntityStatus.FIREWORK_EXPLODE, 17);
|
||||
register(EntityStatus.ANIMAL_EMIT_HEARTS, 18);
|
||||
register(EntityStatus.SQUID_RESET_ROTATION, 19);
|
||||
register(EntityStatus.MOB_EMIT_SMOKE, 20);
|
||||
register(EntityStatus.GUARDIAN_MAKE_SOUND, 21);
|
||||
register(EntityStatus.PLAYER_ENABLE_REDUCED_DEBUG, 22);
|
||||
register(EntityStatus.PLAYER_DISABLE_REDUCED_DEBUG, 23);
|
||||
register(EntityStatus.PLAYER_OP_PERMISSION_LEVEL_0, 24);
|
||||
register(EntityStatus.PLAYER_OP_PERMISSION_LEVEL_1, 25);
|
||||
register(EntityStatus.PLAYER_OP_PERMISSION_LEVEL_2, 26);
|
||||
register(EntityStatus.PLAYER_OP_PERMISSION_LEVEL_3, 27);
|
||||
register(EntityStatus.PLAYER_OP_PERMISSION_LEVEL_4, 28);
|
||||
register(EntityStatus.LIVING_SHIELD_BLOCK, 29);
|
||||
register(EntityStatus.LIVING_SHIELD_BREAK, 30);
|
||||
register(EntityStatus.FISHING_HOOK_PULL_PLAYER, 31);
|
||||
register(EntityStatus.ARMOR_STAND_HIT, 32);
|
||||
register(EntityStatus.LIVING_HURT_THORNS, 33);
|
||||
register(EntityStatus.IRON_GOLEM_EMPTY_HAND, 34);
|
||||
register(EntityStatus.TOTEM_OF_UNDYING_MAKE_SOUND, 35);
|
||||
register(EntityStatus.LIVING_DROWN, 36);
|
||||
register(EntityStatus.LIVING_BURN, 37);
|
||||
register(EntityStatus.DOLPHIN_HAPPY, 38);
|
||||
register(EntityStatus.RAVAGER_STUNNED, 39);
|
||||
register(EntityStatus.OCELOT_TAMING_FAILED, 40);
|
||||
register(EntityStatus.OCELOT_TAMING_SUCCEEDED, 41);
|
||||
register(EntityStatus.VILLAGER_SWEAT, 42);
|
||||
register(EntityStatus.PLAYER_EMIT_CLOUD, 43);
|
||||
register(EntityStatus.LIVING_HURT_SWEET_BERRY_BUSH, 44);
|
||||
register(EntityStatus.FOX_EATING, 45);
|
||||
register(EntityStatus.LIVING_TELEPORT, 46);
|
||||
register(EntityStatus.LIVING_EQUIPMENT_BREAK_MAIN_HAND, 47);
|
||||
register(EntityStatus.LIVING_EQUIPMENT_BREAK_OFF_HAND, 48);
|
||||
register(EntityStatus.LIVING_EQUIPMENT_BREAK_HEAD, 49);
|
||||
register(EntityStatus.LIVING_EQUIPMENT_BREAK_CHEST, 50);
|
||||
register(EntityStatus.LIVING_EQUIPMENT_BREAK_LEGS, 51);
|
||||
register(EntityStatus.LIVING_EQUIPMENT_BREAK_FEET, 52);
|
||||
register(EntityStatus.HONEY_BLOCK_SLIDE, 53);
|
||||
register(EntityStatus.HONEY_BLOCK_LAND, 54);
|
||||
register(EntityStatus.PLAYER_SWAP_SAME_ITEM, 55);
|
||||
register(EntityStatus.WOLF_SHAKE_WATER_STOP, 56);
|
||||
register(EntityStatus.LIVING_FREEZE, 57);
|
||||
register(EntityStatus.GOAT_LOWERING_HEAD, 58);
|
||||
register(EntityStatus.GOAT_STOP_LOWERING_HEAD, 59);
|
||||
register(EntityStatus.MAKE_POOF_PARTICLES, 60);
|
||||
register(EntityEvent.TIPPED_ARROW_EMIT_PARTICLES, 0);
|
||||
register(EntityEvent.RABBIT_JUMP_OR_MINECART_SPAWNER_DELAY_RESET, 1);
|
||||
register(EntityEvent.LIVING_HURT, 2);
|
||||
register(EntityEvent.LIVING_DEATH, 3);
|
||||
register(EntityEvent.IRON_GOLEM_ATTACK, 4);
|
||||
register(EntityEvent.TAMEABLE_TAMING_FAILED, 6);
|
||||
register(EntityEvent.TAMEABLE_TAMING_SUCCEEDED, 7);
|
||||
register(EntityEvent.WOLF_SHAKE_WATER, 8);
|
||||
register(EntityEvent.PLAYER_FINISH_USING_ITEM, 9);
|
||||
register(EntityEvent.SHEEP_GRAZE_OR_TNT_CART_EXPLODE, 10);
|
||||
register(EntityEvent.IRON_GOLEM_HOLD_POPPY, 11);
|
||||
register(EntityEvent.VILLAGER_MATE, 12);
|
||||
register(EntityEvent.VILLAGER_ANGRY, 13);
|
||||
register(EntityEvent.VILLAGER_HAPPY, 14);
|
||||
register(EntityEvent.WITCH_EMIT_PARTICLES, 15);
|
||||
register(EntityEvent.ZOMBIE_VILLAGER_CURE, 16);
|
||||
register(EntityEvent.FIREWORK_EXPLODE, 17);
|
||||
register(EntityEvent.ANIMAL_EMIT_HEARTS, 18);
|
||||
register(EntityEvent.SQUID_RESET_ROTATION, 19);
|
||||
register(EntityEvent.MOB_EMIT_SMOKE, 20);
|
||||
register(EntityEvent.GUARDIAN_MAKE_SOUND, 21);
|
||||
register(EntityEvent.PLAYER_ENABLE_REDUCED_DEBUG, 22);
|
||||
register(EntityEvent.PLAYER_DISABLE_REDUCED_DEBUG, 23);
|
||||
register(EntityEvent.PLAYER_OP_PERMISSION_LEVEL_0, 24);
|
||||
register(EntityEvent.PLAYER_OP_PERMISSION_LEVEL_1, 25);
|
||||
register(EntityEvent.PLAYER_OP_PERMISSION_LEVEL_2, 26);
|
||||
register(EntityEvent.PLAYER_OP_PERMISSION_LEVEL_3, 27);
|
||||
register(EntityEvent.PLAYER_OP_PERMISSION_LEVEL_4, 28);
|
||||
register(EntityEvent.LIVING_SHIELD_BLOCK, 29);
|
||||
register(EntityEvent.LIVING_SHIELD_BREAK, 30);
|
||||
register(EntityEvent.FISHING_HOOK_PULL_PLAYER, 31);
|
||||
register(EntityEvent.ARMOR_STAND_HIT, 32);
|
||||
register(EntityEvent.LIVING_HURT_THORNS, 33);
|
||||
register(EntityEvent.IRON_GOLEM_EMPTY_HAND, 34);
|
||||
register(EntityEvent.TOTEM_OF_UNDYING_MAKE_SOUND, 35);
|
||||
register(EntityEvent.LIVING_DROWN, 36);
|
||||
register(EntityEvent.LIVING_BURN, 37);
|
||||
register(EntityEvent.DOLPHIN_HAPPY, 38);
|
||||
register(EntityEvent.RAVAGER_STUNNED, 39);
|
||||
register(EntityEvent.OCELOT_TAMING_FAILED, 40);
|
||||
register(EntityEvent.OCELOT_TAMING_SUCCEEDED, 41);
|
||||
register(EntityEvent.VILLAGER_SWEAT, 42);
|
||||
register(EntityEvent.PLAYER_EMIT_CLOUD, 43);
|
||||
register(EntityEvent.LIVING_HURT_SWEET_BERRY_BUSH, 44);
|
||||
register(EntityEvent.FOX_EATING, 45);
|
||||
register(EntityEvent.LIVING_TELEPORT, 46);
|
||||
register(EntityEvent.LIVING_EQUIPMENT_BREAK_MAIN_HAND, 47);
|
||||
register(EntityEvent.LIVING_EQUIPMENT_BREAK_OFF_HAND, 48);
|
||||
register(EntityEvent.LIVING_EQUIPMENT_BREAK_HEAD, 49);
|
||||
register(EntityEvent.LIVING_EQUIPMENT_BREAK_CHEST, 50);
|
||||
register(EntityEvent.LIVING_EQUIPMENT_BREAK_LEGS, 51);
|
||||
register(EntityEvent.LIVING_EQUIPMENT_BREAK_FEET, 52);
|
||||
register(EntityEvent.HONEY_BLOCK_SLIDE, 53);
|
||||
register(EntityEvent.HONEY_BLOCK_LAND, 54);
|
||||
register(EntityEvent.PLAYER_SWAP_SAME_ITEM, 55);
|
||||
register(EntityEvent.WOLF_SHAKE_WATER_STOP, 56);
|
||||
register(EntityEvent.LIVING_FREEZE, 57);
|
||||
register(EntityEvent.GOAT_LOWERING_HEAD, 58);
|
||||
register(EntityEvent.GOAT_STOP_LOWERING_HEAD, 59);
|
||||
register(EntityEvent.MAKE_POOF_PARTICLES, 60);
|
||||
|
||||
register(PositionElement.X, 0);
|
||||
register(PositionElement.Y, 1);
|
||||
|
@ -339,122 +251,6 @@ public class MagicValues {
|
|||
register(PositionElement.PITCH, 3);
|
||||
register(PositionElement.YAW, 4);
|
||||
|
||||
register(WeatherEntityType.LIGHTNING_BOLT, 1);
|
||||
|
||||
register(EntityType.AREA_EFFECT_CLOUD, 0);
|
||||
register(EntityType.ARMOR_STAND, 1);
|
||||
register(EntityType.ARROW, 2);
|
||||
register(EntityType.AXOLOTL, 3);
|
||||
register(EntityType.BAT, 4);
|
||||
register(EntityType.BEE, 5);
|
||||
register(EntityType.BLAZE, 6);
|
||||
register(EntityType.BOAT, 7);
|
||||
register(EntityType.CAT, 8);
|
||||
register(EntityType.CAVE_SPIDER, 9);
|
||||
register(EntityType.CHICKEN, 10);
|
||||
register(EntityType.COD, 11);
|
||||
register(EntityType.COW, 12);
|
||||
register(EntityType.CREEPER, 13);
|
||||
register(EntityType.DOLPHIN, 14);
|
||||
register(EntityType.DONKEY, 15);
|
||||
register(EntityType.DRAGON_FIREBALL, 16);
|
||||
register(EntityType.DROWNED, 17);
|
||||
register(EntityType.ELDER_GUARDIAN, 18);
|
||||
register(EntityType.END_CRYSTAL, 19);
|
||||
register(EntityType.ENDER_DRAGON, 20);
|
||||
register(EntityType.ENDERMAN, 21);
|
||||
register(EntityType.ENDERMITE, 22);
|
||||
register(EntityType.EVOKER, 23);
|
||||
register(EntityType.EVOKER_FANGS, 24);
|
||||
register(EntityType.EXPERIENCE_ORB, 25);
|
||||
register(EntityType.EYE_OF_ENDER, 26);
|
||||
register(EntityType.FALLING_BLOCK, 27);
|
||||
register(EntityType.FIREWORK_ROCKET, 28);
|
||||
register(EntityType.FOX, 29);
|
||||
register(EntityType.GHAST, 30);
|
||||
register(EntityType.GIANT, 31);
|
||||
register(EntityType.GLOW_ITEM_FRAME, 32);
|
||||
register(EntityType.GLOW_SQUID, 33);
|
||||
register(EntityType.GOAT, 34);
|
||||
register(EntityType.GUARDIAN, 35);
|
||||
register(EntityType.HOGLIN, 36);
|
||||
register(EntityType.HORSE, 37);
|
||||
register(EntityType.HUSK, 38);
|
||||
register(EntityType.ILLUSIONER, 39);
|
||||
register(EntityType.IRON_GOLEM, 40);
|
||||
register(EntityType.ITEM, 41);
|
||||
register(EntityType.ITEM_FRAME, 42);
|
||||
register(EntityType.FIREBALL, 43);
|
||||
register(EntityType.LEASH_KNOT, 44);
|
||||
register(EntityType.LIGHTNING_BOLT, 45);
|
||||
register(EntityType.LLAMA, 46);
|
||||
register(EntityType.LLAMA_SPIT, 47);
|
||||
register(EntityType.MAGMA_CUBE, 48);
|
||||
register(EntityType.MARKER, 49);
|
||||
register(EntityType.MINECART, 50);
|
||||
register(EntityType.MINECART_CHEST, 51);
|
||||
register(EntityType.MINECART_COMMAND_BLOCK, 52);
|
||||
register(EntityType.MINECART_FURNACE, 53);
|
||||
register(EntityType.MINECART_HOPPER, 54);
|
||||
register(EntityType.MINECART_SPAWNER, 55);
|
||||
register(EntityType.MINECART_TNT, 56);
|
||||
register(EntityType.MULE, 57);
|
||||
register(EntityType.MOOSHROOM, 58);
|
||||
register(EntityType.OCELOT, 59);
|
||||
register(EntityType.PAINTING, 60);
|
||||
register(EntityType.PANDA, 61);
|
||||
register(EntityType.PARROT, 62);
|
||||
register(EntityType.PHANTOM, 63);
|
||||
register(EntityType.PIG, 64);
|
||||
register(EntityType.PIGLIN, 65);
|
||||
register(EntityType.PIGLIN_BRUTE, 66);
|
||||
register(EntityType.PILLAGER, 67);
|
||||
register(EntityType.POLAR_BEAR, 68);
|
||||
register(EntityType.PRIMED_TNT, 69);
|
||||
register(EntityType.PUFFERFISH, 70);
|
||||
register(EntityType.RABBIT, 71);
|
||||
register(EntityType.RAVAGER, 72);
|
||||
register(EntityType.SALMON, 73);
|
||||
register(EntityType.SHEEP, 74);
|
||||
register(EntityType.SHULKER, 75);
|
||||
register(EntityType.SHULKER_BULLET, 76);
|
||||
register(EntityType.SILVERFISH, 77);
|
||||
register(EntityType.SKELETON, 78);
|
||||
register(EntityType.SKELETON_HORSE, 79);
|
||||
register(EntityType.SLIME, 80);
|
||||
register(EntityType.SMALL_FIREBALL, 81);
|
||||
register(EntityType.SNOW_GOLEM, 82);
|
||||
register(EntityType.SNOWBALL, 83);
|
||||
register(EntityType.SPECTRAL_ARROW, 84);
|
||||
register(EntityType.SPIDER, 85);
|
||||
register(EntityType.SQUID, 86);
|
||||
register(EntityType.STRAY, 87);
|
||||
register(EntityType.STRIDER, 88);
|
||||
register(EntityType.THROWN_EGG, 89);
|
||||
register(EntityType.THROWN_ENDERPEARL, 90);
|
||||
register(EntityType.THROWN_EXP_BOTTLE, 91);
|
||||
register(EntityType.THROWN_POTION, 92);
|
||||
register(EntityType.TRIDENT, 93);
|
||||
register(EntityType.TRADER_LLAMA, 94);
|
||||
register(EntityType.TROPICAL_FISH, 95);
|
||||
register(EntityType.TURTLE, 96);
|
||||
register(EntityType.VEX, 97);
|
||||
register(EntityType.VILLAGER, 98);
|
||||
register(EntityType.VINDICATOR, 99);
|
||||
register(EntityType.WANDERING_TRADER, 100);
|
||||
register(EntityType.WITCH, 101);
|
||||
register(EntityType.WITHER, 102);
|
||||
register(EntityType.WITHER_SKELETON, 103);
|
||||
register(EntityType.WITHER_SKULL, 104);
|
||||
register(EntityType.WOLF, 105);
|
||||
register(EntityType.ZOGLIN, 106);
|
||||
register(EntityType.ZOMBIE, 107);
|
||||
register(EntityType.ZOMBIE_HORSE, 108);
|
||||
register(EntityType.ZOMBIE_VILLAGER, 109);
|
||||
register(EntityType.ZOMBIFIED_PIGLIN, 110);
|
||||
register(EntityType.PLAYER, 111);
|
||||
register(EntityType.FISHING_BOBBER, 112);
|
||||
|
||||
register(MinecartType.NORMAL, 0);
|
||||
register(MinecartType.CHEST, 1);
|
||||
register(MinecartType.POWERED, 2);
|
||||
|
@ -463,13 +259,6 @@ public class MagicValues {
|
|||
register(MinecartType.HOPPER, 5);
|
||||
register(MinecartType.COMMAND_BLOCK, 6);
|
||||
|
||||
register(HangingDirection.DOWN, 0);
|
||||
register(HangingDirection.UP, 1);
|
||||
register(HangingDirection.NORTH, 2);
|
||||
register(HangingDirection.SOUTH, 3);
|
||||
register(HangingDirection.WEST, 4);
|
||||
register(HangingDirection.EAST, 5);
|
||||
|
||||
register(PaintingType.KEBAB, 0);
|
||||
register(PaintingType.AZTEC, 1);
|
||||
register(PaintingType.ALBAN, 2);
|
||||
|
@ -558,30 +347,30 @@ public class MagicValues {
|
|||
register(MapIconType.BLACK_BANNER, 25);
|
||||
register(MapIconType.TREASURE_MARKER, 26);
|
||||
|
||||
register(WindowType.GENERIC_9X1, 0);
|
||||
register(WindowType.GENERIC_9X2, 1);
|
||||
register(WindowType.GENERIC_9X3, 2);
|
||||
register(WindowType.GENERIC_9X4, 3);
|
||||
register(WindowType.GENERIC_9X5, 4);
|
||||
register(WindowType.GENERIC_9X6, 5);
|
||||
register(WindowType.GENERIC_3X3, 6);
|
||||
register(WindowType.ANVIL, 7);
|
||||
register(WindowType.BEACON, 8);
|
||||
register(WindowType.BLAST_FURNACE, 9);
|
||||
register(WindowType.BREWING_STAND, 10);
|
||||
register(WindowType.CRAFTING, 11);
|
||||
register(WindowType.ENCHANTMENT, 12);
|
||||
register(WindowType.FURNACE, 13);
|
||||
register(WindowType.GRINDSTONE, 14);
|
||||
register(WindowType.HOPPER, 15);
|
||||
register(WindowType.LECTERN, 16);
|
||||
register(WindowType.LOOM, 17);
|
||||
register(WindowType.MERCHANT, 18);
|
||||
register(WindowType.SHULKER_BOX, 19);
|
||||
register(WindowType.SMITHING, 20);
|
||||
register(WindowType.SMOKER, 21);
|
||||
register(WindowType.CARTOGRAPHY, 22);
|
||||
register(WindowType.STONECUTTER, 23);
|
||||
register(ContainerType.GENERIC_9X1, 0);
|
||||
register(ContainerType.GENERIC_9X2, 1);
|
||||
register(ContainerType.GENERIC_9X3, 2);
|
||||
register(ContainerType.GENERIC_9X4, 3);
|
||||
register(ContainerType.GENERIC_9X5, 4);
|
||||
register(ContainerType.GENERIC_9X6, 5);
|
||||
register(ContainerType.GENERIC_3X3, 6);
|
||||
register(ContainerType.ANVIL, 7);
|
||||
register(ContainerType.BEACON, 8);
|
||||
register(ContainerType.BLAST_FURNACE, 9);
|
||||
register(ContainerType.BREWING_STAND, 10);
|
||||
register(ContainerType.CRAFTING, 11);
|
||||
register(ContainerType.ENCHANTMENT, 12);
|
||||
register(ContainerType.FURNACE, 13);
|
||||
register(ContainerType.GRINDSTONE, 14);
|
||||
register(ContainerType.HOPPER, 15);
|
||||
register(ContainerType.LECTERN, 16);
|
||||
register(ContainerType.LOOM, 17);
|
||||
register(ContainerType.MERCHANT, 18);
|
||||
register(ContainerType.SHULKER_BOX, 19);
|
||||
register(ContainerType.SMITHING, 20);
|
||||
register(ContainerType.SMOKER, 21);
|
||||
register(ContainerType.CARTOGRAPHY, 22);
|
||||
register(ContainerType.STONECUTTER, 23);
|
||||
|
||||
register(BrewingStandProperty.BREW_TIME, 0);
|
||||
|
||||
|
@ -600,46 +389,18 @@ public class MagicValues {
|
|||
|
||||
register(AnvilProperty.MAXIMUM_COST, 0);
|
||||
|
||||
register(BlockBreakStage.RESET, -1);
|
||||
register(BlockBreakStage.STAGE_1, 0);
|
||||
register(BlockBreakStage.STAGE_2, 1);
|
||||
register(BlockBreakStage.STAGE_3, 2);
|
||||
register(BlockBreakStage.STAGE_4, 3);
|
||||
register(BlockBreakStage.STAGE_5, 4);
|
||||
register(BlockBreakStage.STAGE_6, 5);
|
||||
register(BlockBreakStage.STAGE_7, 6);
|
||||
register(BlockBreakStage.STAGE_8, 7);
|
||||
register(BlockBreakStage.STAGE_9, 8);
|
||||
register(BlockBreakStage.STAGE_10, 9);
|
||||
register(BlockBreakStage.RESET, 255);
|
||||
|
||||
register(UpdatedTileType.MOB_SPAWNER, 1);
|
||||
register(UpdatedTileType.COMMAND_BLOCK, 2);
|
||||
register(UpdatedTileType.BEACON, 3);
|
||||
register(UpdatedTileType.SKULL, 4);
|
||||
register(UpdatedTileType.CONDUIT, 5);
|
||||
register(UpdatedTileType.BANNER, 6);
|
||||
register(UpdatedTileType.STRUCTURE_BLOCK, 7);
|
||||
register(UpdatedTileType.END_GATEWAY, 8);
|
||||
register(UpdatedTileType.SIGN, 9);
|
||||
register(UpdatedTileType.SHULKER_BOX, 10);
|
||||
register(UpdatedTileType.BED, 11);
|
||||
register(UpdatedTileType.JIGSAW_BLOCK, 12);
|
||||
register(UpdatedTileType.CAMPFIRE, 13);
|
||||
register(UpdatedTileType.BEEHIVE, 14);
|
||||
|
||||
register(ClientNotification.INVALID_BED, 0);
|
||||
register(ClientNotification.STOP_RAIN, 1);
|
||||
register(ClientNotification.START_RAIN, 2);
|
||||
register(ClientNotification.CHANGE_GAMEMODE, 3);
|
||||
register(ClientNotification.ENTER_CREDITS, 4);
|
||||
register(ClientNotification.DEMO_MESSAGE, 5);
|
||||
register(ClientNotification.ARROW_HIT_PLAYER, 6);
|
||||
register(ClientNotification.RAIN_STRENGTH, 7);
|
||||
register(ClientNotification.THUNDER_STRENGTH, 8);
|
||||
register(ClientNotification.PUFFERFISH_STING_SOUND, 9);
|
||||
register(ClientNotification.AFFECTED_BY_ELDER_GUARDIAN, 10);
|
||||
register(ClientNotification.ENABLE_RESPAWN_SCREEN, 11);
|
||||
register(GameEvent.INVALID_BED, 0);
|
||||
register(GameEvent.STOP_RAIN, 1);
|
||||
register(GameEvent.START_RAIN, 2);
|
||||
register(GameEvent.CHANGE_GAMEMODE, 3);
|
||||
register(GameEvent.ENTER_CREDITS, 4);
|
||||
register(GameEvent.DEMO_MESSAGE, 5);
|
||||
register(GameEvent.ARROW_HIT_PLAYER, 6);
|
||||
register(GameEvent.RAIN_STRENGTH, 7);
|
||||
register(GameEvent.THUNDER_STRENGTH, 8);
|
||||
register(GameEvent.PUFFERFISH_STING_SOUND, 9);
|
||||
register(GameEvent.AFFECTED_BY_ELDER_GUARDIAN, 10);
|
||||
register(GameEvent.ENABLE_RESPAWN_SCREEN, 11);
|
||||
|
||||
register(CommandBlockMode.SEQUENCE, 0);
|
||||
register(CommandBlockMode.AUTO, 1);
|
||||
|
@ -798,91 +559,91 @@ public class MagicValues {
|
|||
register(PistonValue.WEST, 4);
|
||||
register(PistonValue.EAST, 5);
|
||||
|
||||
register(SoundEffect.BLOCK_DISPENSER_DISPENSE, 1000);
|
||||
register(SoundEffect.BLOCK_DISPENSER_FAIL, 1001);
|
||||
register(SoundEffect.BLOCK_DISPENSER_LAUNCH, 1002);
|
||||
register(SoundEffect.ENTITY_ENDEREYE_LAUNCH, 1003);
|
||||
register(SoundEffect.ENTITY_FIREWORK_SHOOT, 1004);
|
||||
register(SoundEffect.BLOCK_IRON_DOOR_OPEN, 1005);
|
||||
register(SoundEffect.BLOCK_WOODEN_DOOR_OPEN, 1006);
|
||||
register(SoundEffect.BLOCK_WOODEN_TRAPDOOR_OPEN, 1007);
|
||||
register(SoundEffect.BLOCK_FENCE_GATE_OPEN, 1008);
|
||||
register(SoundEffect.BLOCK_FIRE_EXTINGUISH, 1009);
|
||||
register(SoundEffect.RECORD, 1010);
|
||||
register(SoundEffect.BLOCK_IRON_DOOR_CLOSE, 1011);
|
||||
register(SoundEffect.BLOCK_WOODEN_DOOR_CLOSE, 1012);
|
||||
register(SoundEffect.BLOCK_WOODEN_TRAPDOOR_CLOSE, 1013);
|
||||
register(SoundEffect.BLOCK_FENCE_GATE_CLOSE, 1014);
|
||||
register(SoundEffect.ENTITY_GHAST_WARN, 1015);
|
||||
register(SoundEffect.ENTITY_GHAST_SHOOT, 1016);
|
||||
register(SoundEffect.ENTITY_ENDERDRAGON_SHOOT, 1017);
|
||||
register(SoundEffect.ENTITY_BLAZE_SHOOT, 1018);
|
||||
register(SoundEffect.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, 1019);
|
||||
register(SoundEffect.ENTITY_ZOMBIE_ATTACK_DOOR_IRON, 1020);
|
||||
register(SoundEffect.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, 1021);
|
||||
register(SoundEffect.ENTITY_WITHER_BREAK_BLOCK, 1022);
|
||||
register(SoundEffect.ENTITY_WITHER_SPAWN, 1023);
|
||||
register(SoundEffect.ENTITY_WITHER_SHOOT, 1024);
|
||||
register(SoundEffect.ENTITY_BAT_TAKEOFF, 1025);
|
||||
register(SoundEffect.ENTITY_ZOMBIE_INFECT, 1026);
|
||||
register(SoundEffect.ENTITY_ZOMBIE_VILLAGER_CONVERTED, 1027);
|
||||
register(SoundEffect.ENTITY_ENDERDRAGON_DEATH, 1028);
|
||||
register(SoundEffect.BLOCK_ANVIL_DESTROY, 1029);
|
||||
register(SoundEffect.BLOCK_ANVIL_USE, 1030);
|
||||
register(SoundEffect.BLOCK_ANVIL_LAND, 1031);
|
||||
register(SoundEffect.BLOCK_PORTAL_TRAVEL, 1032);
|
||||
register(SoundEffect.BLOCK_CHORUS_FLOWER_GROW, 1033);
|
||||
register(SoundEffect.BLOCK_CHORUS_FLOWER_DEATH, 1034);
|
||||
register(SoundEffect.BLOCK_BREWING_STAND_BREW, 1035);
|
||||
register(SoundEffect.BLOCK_IRON_TRAPDOOR_CLOSE, 1036);
|
||||
register(SoundEffect.BLOCK_IRON_TRAPDOOR_OPEN, 1037);
|
||||
register(SoundEffect.BLOCK_END_PORTAL_SPAWN, 1038);
|
||||
register(SoundEffect.ENTITY_PHANTOM_BITE, 1039);
|
||||
register(SoundEffect.ENTITY_ZOMBIE_CONVERTED_TO_DROWNED, 1040);
|
||||
register(SoundEffect.ENTITY_HUSK_CONVERTED_TO_ZOMBIE, 1041);
|
||||
register(SoundEffect.BLOCK_GRINDSTONE_USE, 1042);
|
||||
register(SoundEffect.ITEM_BOOK_PAGE_TURN, 1043);
|
||||
register(SoundEffect.BLOCK_SMITHING_TABLE_USE, 1044);
|
||||
register(SoundEffect.POINTED_DRIPSTONE_LAND, 1045);
|
||||
register(SoundEffect.DRIP_LAVA_INTO_CAULDRON, 1046);
|
||||
register(SoundEffect.DRIP_WATER_INTO_CAULDRON, 1047);
|
||||
register(SoundEffect.ENTITY_SKELETON_CONVERTED_TO_STRAY, 1048);
|
||||
register(SoundEffect.ENTITY_ENDERDRAGON_GROWL, 3001);
|
||||
register(SoundEvent.BLOCK_DISPENSER_DISPENSE, 1000);
|
||||
register(SoundEvent.BLOCK_DISPENSER_FAIL, 1001);
|
||||
register(SoundEvent.BLOCK_DISPENSER_LAUNCH, 1002);
|
||||
register(SoundEvent.ENTITY_ENDEREYE_LAUNCH, 1003);
|
||||
register(SoundEvent.ENTITY_FIREWORK_SHOOT, 1004);
|
||||
register(SoundEvent.BLOCK_IRON_DOOR_OPEN, 1005);
|
||||
register(SoundEvent.BLOCK_WOODEN_DOOR_OPEN, 1006);
|
||||
register(SoundEvent.BLOCK_WOODEN_TRAPDOOR_OPEN, 1007);
|
||||
register(SoundEvent.BLOCK_FENCE_GATE_OPEN, 1008);
|
||||
register(SoundEvent.BLOCK_FIRE_EXTINGUISH, 1009);
|
||||
register(SoundEvent.RECORD, 1010);
|
||||
register(SoundEvent.BLOCK_IRON_DOOR_CLOSE, 1011);
|
||||
register(SoundEvent.BLOCK_WOODEN_DOOR_CLOSE, 1012);
|
||||
register(SoundEvent.BLOCK_WOODEN_TRAPDOOR_CLOSE, 1013);
|
||||
register(SoundEvent.BLOCK_FENCE_GATE_CLOSE, 1014);
|
||||
register(SoundEvent.ENTITY_GHAST_WARN, 1015);
|
||||
register(SoundEvent.ENTITY_GHAST_SHOOT, 1016);
|
||||
register(SoundEvent.ENTITY_ENDERDRAGON_SHOOT, 1017);
|
||||
register(SoundEvent.ENTITY_BLAZE_SHOOT, 1018);
|
||||
register(SoundEvent.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, 1019);
|
||||
register(SoundEvent.ENTITY_ZOMBIE_ATTACK_DOOR_IRON, 1020);
|
||||
register(SoundEvent.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, 1021);
|
||||
register(SoundEvent.ENTITY_WITHER_BREAK_BLOCK, 1022);
|
||||
register(SoundEvent.ENTITY_WITHER_SPAWN, 1023);
|
||||
register(SoundEvent.ENTITY_WITHER_SHOOT, 1024);
|
||||
register(SoundEvent.ENTITY_BAT_TAKEOFF, 1025);
|
||||
register(SoundEvent.ENTITY_ZOMBIE_INFECT, 1026);
|
||||
register(SoundEvent.ENTITY_ZOMBIE_VILLAGER_CONVERTED, 1027);
|
||||
register(SoundEvent.ENTITY_ENDERDRAGON_DEATH, 1028);
|
||||
register(SoundEvent.BLOCK_ANVIL_DESTROY, 1029);
|
||||
register(SoundEvent.BLOCK_ANVIL_USE, 1030);
|
||||
register(SoundEvent.BLOCK_ANVIL_LAND, 1031);
|
||||
register(SoundEvent.BLOCK_PORTAL_TRAVEL, 1032);
|
||||
register(SoundEvent.BLOCK_CHORUS_FLOWER_GROW, 1033);
|
||||
register(SoundEvent.BLOCK_CHORUS_FLOWER_DEATH, 1034);
|
||||
register(SoundEvent.BLOCK_BREWING_STAND_BREW, 1035);
|
||||
register(SoundEvent.BLOCK_IRON_TRAPDOOR_CLOSE, 1036);
|
||||
register(SoundEvent.BLOCK_IRON_TRAPDOOR_OPEN, 1037);
|
||||
register(SoundEvent.BLOCK_END_PORTAL_SPAWN, 1038);
|
||||
register(SoundEvent.ENTITY_PHANTOM_BITE, 1039);
|
||||
register(SoundEvent.ENTITY_ZOMBIE_CONVERTED_TO_DROWNED, 1040);
|
||||
register(SoundEvent.ENTITY_HUSK_CONVERTED_TO_ZOMBIE, 1041);
|
||||
register(SoundEvent.BLOCK_GRINDSTONE_USE, 1042);
|
||||
register(SoundEvent.ITEM_BOOK_PAGE_TURN, 1043);
|
||||
register(SoundEvent.BLOCK_SMITHING_TABLE_USE, 1044);
|
||||
register(SoundEvent.POINTED_DRIPSTONE_LAND, 1045);
|
||||
register(SoundEvent.DRIP_LAVA_INTO_CAULDRON, 1046);
|
||||
register(SoundEvent.DRIP_WATER_INTO_CAULDRON, 1047);
|
||||
register(SoundEvent.ENTITY_SKELETON_CONVERTED_TO_STRAY, 1048);
|
||||
register(SoundEvent.ENTITY_ENDERDRAGON_GROWL, 3001);
|
||||
|
||||
register(ParticleEffect.COMPOSTER, 1500);
|
||||
register(ParticleEffect.BLOCK_LAVA_EXTINGUISH, 1501);
|
||||
register(ParticleEffect.BLOCK_REDSTONE_TORCH_BURNOUT, 1502);
|
||||
register(ParticleEffect.BLOCK_END_PORTAL_FRAME_FILL, 1503);
|
||||
register(ParticleEffect.DRIPSTONE_DRIP, 1504);
|
||||
register(ParticleEffect.BONEMEAL_GROW_WITH_SOUND, 1505);
|
||||
register(ParticleEffect.SMOKE, 2000);
|
||||
register(ParticleEffect.BREAK_BLOCK, 2001);
|
||||
register(ParticleEffect.BREAK_SPLASH_POTION, 2002);
|
||||
register(ParticleEffect.BREAK_EYE_OF_ENDER, 2003);
|
||||
register(ParticleEffect.MOB_SPAWN, 2004);
|
||||
register(ParticleEffect.BONEMEAL_GROW, 2005);
|
||||
register(ParticleEffect.ENDERDRAGON_FIREBALL_EXPLODE, 2006);
|
||||
register(ParticleEffect.BREAK_SPLASH_POTION, 2007);
|
||||
register(ParticleEffect.EXPLOSION, 2008);
|
||||
register(ParticleEffect.EVAPORATE, 2009);
|
||||
register(ParticleEffect.END_GATEWAY_SPAWN, 3000);
|
||||
register(ParticleEffect.ELECTRIC_SPARK, 3002);
|
||||
register(ParticleEffect.WAX_ON, 3003);
|
||||
register(ParticleEffect.WAX_OFF, 3004);
|
||||
register(ParticleEffect.SCRAPE, 3005);
|
||||
register(ParticleEvent.COMPOSTER, 1500);
|
||||
register(ParticleEvent.BLOCK_LAVA_EXTINGUISH, 1501);
|
||||
register(ParticleEvent.BLOCK_REDSTONE_TORCH_BURNOUT, 1502);
|
||||
register(ParticleEvent.BLOCK_END_PORTAL_FRAME_FILL, 1503);
|
||||
register(ParticleEvent.DRIPSTONE_DRIP, 1504);
|
||||
register(ParticleEvent.BONEMEAL_GROW_WITH_SOUND, 1505);
|
||||
register(ParticleEvent.SMOKE, 2000);
|
||||
register(ParticleEvent.BREAK_BLOCK, 2001);
|
||||
register(ParticleEvent.BREAK_SPLASH_POTION, 2002);
|
||||
register(ParticleEvent.BREAK_EYE_OF_ENDER, 2003);
|
||||
register(ParticleEvent.MOB_SPAWN, 2004);
|
||||
register(ParticleEvent.BONEMEAL_GROW, 2005);
|
||||
register(ParticleEvent.ENDERDRAGON_FIREBALL_EXPLODE, 2006);
|
||||
register(ParticleEvent.BREAK_SPLASH_POTION, 2007);
|
||||
register(ParticleEvent.EXPLOSION, 2008);
|
||||
register(ParticleEvent.EVAPORATE, 2009);
|
||||
register(ParticleEvent.END_GATEWAY_SPAWN, 3000);
|
||||
register(ParticleEvent.ELECTRIC_SPARK, 3002);
|
||||
register(ParticleEvent.WAX_ON, 3003);
|
||||
register(ParticleEvent.WAX_OFF, 3004);
|
||||
register(ParticleEvent.SCRAPE, 3005);
|
||||
|
||||
register(SmokeEffectData.DOWN, 0);
|
||||
register(SmokeEffectData.UP, 1);
|
||||
register(SmokeEffectData.NORTH, 2);
|
||||
register(SmokeEffectData.SOUTH, 3);
|
||||
register(SmokeEffectData.WEST, 4);
|
||||
register(SmokeEffectData.EAST, 5);
|
||||
register(SmokeEventData.DOWN, 0);
|
||||
register(SmokeEventData.UP, 1);
|
||||
register(SmokeEventData.NORTH, 2);
|
||||
register(SmokeEventData.SOUTH, 3);
|
||||
register(SmokeEventData.WEST, 4);
|
||||
register(SmokeEventData.EAST, 5);
|
||||
|
||||
register(ComposterEffectData.FILL, 0);
|
||||
register(ComposterEffectData.FILL_SUCCESS, 1);
|
||||
register(ComposterEventData.FILL, 0);
|
||||
register(ComposterEventData.FILL_SUCCESS, 1);
|
||||
|
||||
register(DragonFireballEffectData.NO_SOUND, 0);
|
||||
register(DragonFireballEffectData.HAS_SOUND, 1);
|
||||
register(DragonFireballEventData.NO_SOUND, 0);
|
||||
register(DragonFireballEventData.HAS_SOUND, 1);
|
||||
|
||||
register(NameTagVisibility.ALWAYS, "");
|
||||
register(NameTagVisibility.ALWAYS, "always");
|
||||
|
@ -896,29 +657,6 @@ public class MagicValues {
|
|||
register(CollisionRule.PUSH_OTHER_TEAMS, "pushOtherTeams");
|
||||
register(CollisionRule.PUSH_OWN_TEAM, "pushOwnTeam");
|
||||
|
||||
register(TeamColor.BLACK, 0);
|
||||
register(TeamColor.DARK_BLUE, 1);
|
||||
register(TeamColor.DARK_GREEN, 2);
|
||||
register(TeamColor.DARK_AQUA, 3);
|
||||
register(TeamColor.DARK_RED, 4);
|
||||
register(TeamColor.DARK_PURPLE, 5);
|
||||
register(TeamColor.GOLD, 6);
|
||||
register(TeamColor.GRAY, 7);
|
||||
register(TeamColor.DARK_GRAY, 8);
|
||||
register(TeamColor.BLUE, 9);
|
||||
register(TeamColor.GREEN, 10);
|
||||
register(TeamColor.AQUA, 11);
|
||||
register(TeamColor.RED, 12);
|
||||
register(TeamColor.LIGHT_PURPLE, 13);
|
||||
register(TeamColor.YELLOW, 14);
|
||||
register(TeamColor.WHITE, 15);
|
||||
register(TeamColor.OBFUSCATED, 16);
|
||||
register(TeamColor.BOLD, 17);
|
||||
register(TeamColor.STRIKETHROUGH, 18);
|
||||
register(TeamColor.UNDERLINED, 19);
|
||||
register(TeamColor.ITALIC, 20);
|
||||
register(TeamColor.NONE, 21);
|
||||
|
||||
register(ScoreType.INTEGER, 0);
|
||||
register(ScoreType.HEARTS, 1);
|
||||
|
||||
|
@ -976,14 +714,6 @@ public class MagicValues {
|
|||
register(BossBarDivision.NOTCHES_12, 3);
|
||||
register(BossBarDivision.NOTCHES_20, 4);
|
||||
|
||||
register(BlockFace.DOWN, 0);
|
||||
register(BlockFace.UP, 1);
|
||||
register(BlockFace.NORTH, 2);
|
||||
register(BlockFace.SOUTH, 3);
|
||||
register(BlockFace.WEST, 4);
|
||||
register(BlockFace.EAST, 5);
|
||||
register(BlockFace.SPECIAL, 255);
|
||||
|
||||
register(EquipmentSlot.MAIN_HAND, 0);
|
||||
register(EquipmentSlot.OFF_HAND, 1);
|
||||
register(EquipmentSlot.BOOTS, 2);
|
||||
|
@ -1088,11 +818,6 @@ public class MagicValues {
|
|||
register(SoundCategory.PLAYER, 7);
|
||||
register(SoundCategory.AMBIENT, 8);
|
||||
register(SoundCategory.VOICE, 9);
|
||||
|
||||
for (BuiltinSound sound : BuiltinSound.values()) {
|
||||
register(sound, sound.ordinal());
|
||||
register(sound, sound.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private MagicValues() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data;
|
||||
|
||||
public enum SubProtocol {
|
||||
public enum ProtocolState {
|
||||
HANDSHAKE,
|
||||
LOGIN,
|
||||
GAME,
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game;
|
||||
|
||||
public enum ClientRequest {
|
||||
public enum ClientCommand {
|
||||
RESPAWN,
|
||||
STATS;
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.chunk;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.GlobalPalette;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.ListPalette;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.MapPalette;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.Palette;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
@Setter(AccessLevel.NONE)
|
||||
@AllArgsConstructor
|
||||
public class Chunk {
|
||||
private static final int CHUNK_SIZE = 4096;
|
||||
private static final int MIN_PALETTE_BITS_PER_ENTRY = 4;
|
||||
private static final int MAX_PALETTE_BITS_PER_ENTRY = 8;
|
||||
private static final int GLOBAL_PALETTE_BITS_PER_ENTRY = 14;
|
||||
|
||||
private static final int AIR = 0;
|
||||
|
||||
private int blockCount;
|
||||
private @NonNull Palette palette;
|
||||
private @NonNull BitStorage storage;
|
||||
|
||||
public Chunk() {
|
||||
this(0, new ListPalette(MIN_PALETTE_BITS_PER_ENTRY), new BitStorage(MIN_PALETTE_BITS_PER_ENTRY, CHUNK_SIZE));
|
||||
}
|
||||
|
||||
public static Chunk read(NetInput in) throws IOException {
|
||||
int blockCount = in.readShort();
|
||||
int bitsPerEntry = in.readUnsignedByte();
|
||||
|
||||
Palette palette = readPalette(bitsPerEntry, in);
|
||||
|
||||
BitStorage storage = new BitStorage(bitsPerEntry, CHUNK_SIZE, in.readLongs(in.readVarInt()));
|
||||
return new Chunk(blockCount, palette, storage);
|
||||
}
|
||||
|
||||
public static void write(NetOutput out, Chunk chunk) throws IOException {
|
||||
out.writeShort(chunk.blockCount);
|
||||
out.writeByte(chunk.storage.getBitsPerEntry());
|
||||
|
||||
if (!(chunk.palette instanceof GlobalPalette)) {
|
||||
int paletteLength = chunk.palette.size();
|
||||
out.writeVarInt(paletteLength);
|
||||
for (int i = 0; i < paletteLength; i++) {
|
||||
out.writeVarInt(chunk.palette.idToState(i));
|
||||
}
|
||||
}
|
||||
|
||||
long[] data = chunk.storage.getData();
|
||||
out.writeVarInt(data.length);
|
||||
out.writeLongs(data);
|
||||
}
|
||||
|
||||
public int get(int x, int y, int z) {
|
||||
int id = this.storage.get(index(x, y, z));
|
||||
return this.palette.idToState(id);
|
||||
}
|
||||
|
||||
public void set(int x, int y, int z, @NonNull int state) {
|
||||
int id = this.palette.stateToId(state);
|
||||
if (id == -1) {
|
||||
this.resizePalette();
|
||||
id = this.palette.stateToId(state);
|
||||
}
|
||||
|
||||
int index = index(x, y, z);
|
||||
int curr = this.storage.get(index);
|
||||
if (state != AIR && curr == AIR) {
|
||||
this.blockCount++;
|
||||
} else if (state == AIR && curr != AIR) {
|
||||
this.blockCount--;
|
||||
}
|
||||
|
||||
this.storage.set(index, id);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.blockCount == 0;
|
||||
}
|
||||
|
||||
private int sanitizeBitsPerEntry(int bitsPerEntry) {
|
||||
if (bitsPerEntry <= MAX_PALETTE_BITS_PER_ENTRY) {
|
||||
return Math.max(MIN_PALETTE_BITS_PER_ENTRY, bitsPerEntry);
|
||||
} else {
|
||||
return GLOBAL_PALETTE_BITS_PER_ENTRY;
|
||||
}
|
||||
}
|
||||
|
||||
private void resizePalette() {
|
||||
Palette oldPalette = this.palette;
|
||||
BitStorage oldData = this.storage;
|
||||
|
||||
int bitsPerEntry = sanitizeBitsPerEntry(oldData.getBitsPerEntry() + 1);
|
||||
this.palette = createPalette(bitsPerEntry);
|
||||
this.storage = new BitStorage(bitsPerEntry, CHUNK_SIZE);
|
||||
|
||||
for (int i = 0; i < CHUNK_SIZE; i++) {
|
||||
this.storage.set(i, this.palette.stateToId(oldPalette.idToState(oldData.get(i))));
|
||||
}
|
||||
}
|
||||
|
||||
private static Palette createPalette(int bitsPerEntry) {
|
||||
if (bitsPerEntry <= MIN_PALETTE_BITS_PER_ENTRY) {
|
||||
return new ListPalette(bitsPerEntry);
|
||||
} else if (bitsPerEntry <= MAX_PALETTE_BITS_PER_ENTRY) {
|
||||
return new MapPalette(bitsPerEntry);
|
||||
} else {
|
||||
return new GlobalPalette();
|
||||
}
|
||||
}
|
||||
|
||||
private static Palette readPalette(int bitsPerEntry, NetInput in) throws IOException {
|
||||
if (bitsPerEntry <= MIN_PALETTE_BITS_PER_ENTRY) {
|
||||
return new ListPalette(bitsPerEntry, in);
|
||||
} else if (bitsPerEntry <= MAX_PALETTE_BITS_PER_ENTRY) {
|
||||
return new MapPalette(bitsPerEntry, in);
|
||||
} else {
|
||||
return new GlobalPalette();
|
||||
}
|
||||
}
|
||||
|
||||
private static int index(int x, int y, int z) {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.chunk;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.PaletteType;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
@Setter(AccessLevel.NONE)
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class ChunkSection {
|
||||
|
||||
private static final int AIR = 0;
|
||||
|
||||
private int blockCount;
|
||||
private @NonNull DataPalette chunkData;
|
||||
@Getter
|
||||
private @NonNull DataPalette biomeData;
|
||||
|
||||
public ChunkSection() {
|
||||
this(0, DataPalette.createForChunk(), DataPalette.createForBiome(4));
|
||||
}
|
||||
|
||||
public static ChunkSection read(NetInput in, int globalBiomePaletteBits) throws IOException {
|
||||
int blockCount = in.readShort();
|
||||
|
||||
DataPalette chunkPalette = DataPalette.read(in, PaletteType.CHUNK, DataPalette.GLOBAL_PALETTE_BITS_PER_ENTRY);
|
||||
DataPalette biomePalette = DataPalette.read(in, PaletteType.BIOME, globalBiomePaletteBits);
|
||||
return new ChunkSection(blockCount, chunkPalette, biomePalette);
|
||||
}
|
||||
|
||||
public static void write(NetOutput out, ChunkSection section, int globalBiomePaletteBits) throws IOException {
|
||||
out.writeShort(section.blockCount);
|
||||
DataPalette.write(out, section.chunkData);
|
||||
DataPalette.write(out, section.biomeData);
|
||||
}
|
||||
|
||||
public int getBlock(int x, int y, int z) {
|
||||
return this.chunkData.get(x, y, z);
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, int state) {
|
||||
int curr = this.chunkData.set(x, y, z, state);
|
||||
if (state != AIR && curr == AIR) {
|
||||
this.blockCount++;
|
||||
} else if (state == AIR && curr != AIR) {
|
||||
this.blockCount--;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBlockCountEmpty() {
|
||||
return this.blockCount == 0;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.chunk;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Data
|
||||
public class Column {
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final @NonNull Chunk[] chunks;
|
||||
private final @NonNull CompoundTag[] tileEntities;
|
||||
private final @NonNull CompoundTag heightMaps;
|
||||
private final @NonNull int[] biomeData;
|
||||
|
||||
/**
|
||||
* @deprecated Non-full chunks no longer exist since 1.17.
|
||||
*/
|
||||
@Deprecated
|
||||
public Column(int x, int z, @NonNull Chunk[] chunks, @NonNull CompoundTag[] tileEntities, @NonNull CompoundTag heightMaps) {
|
||||
this(x, z, chunks, tileEntities, heightMaps, new int[1024]);
|
||||
}
|
||||
|
||||
public Column(int x, int z, @NonNull Chunk[] chunks, @NonNull CompoundTag[] tileEntities, @NonNull CompoundTag heightMaps, @NonNull int[] biomeData) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.chunks = Arrays.copyOf(chunks, chunks.length);
|
||||
this.biomeData = biomeData != null ? Arrays.copyOf(biomeData, biomeData.length) : null;
|
||||
this.tileEntities = tileEntities != null ? tileEntities : new CompoundTag[0];
|
||||
this.heightMaps = heightMaps;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.chunk;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.*;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class DataPalette {
|
||||
public static final int GLOBAL_PALETTE_BITS_PER_ENTRY = 14;
|
||||
|
||||
private @NonNull Palette palette;
|
||||
private BitStorage storage;
|
||||
private final PaletteType paletteType;
|
||||
private final int globalPaletteBits;
|
||||
|
||||
public static DataPalette createForChunk() {
|
||||
return createForChunk(GLOBAL_PALETTE_BITS_PER_ENTRY);
|
||||
}
|
||||
|
||||
public static DataPalette createForChunk(int globalPaletteBits) {
|
||||
return createEmpty(PaletteType.CHUNK, globalPaletteBits);
|
||||
}
|
||||
|
||||
public static DataPalette createForBiome(int globalPaletteBits) {
|
||||
return createEmpty(PaletteType.BIOME, globalPaletteBits);
|
||||
}
|
||||
|
||||
public static DataPalette createEmpty(PaletteType paletteType, int globalPaletteBits) {
|
||||
return new DataPalette(new ListPalette(paletteType.getMinBitsPerEntry()),
|
||||
new BitStorage(paletteType.getMinBitsPerEntry(), paletteType.getStorageSize()), paletteType, globalPaletteBits);
|
||||
}
|
||||
|
||||
public static DataPalette read(NetInput in, PaletteType paletteType, int globalPaletteBits) throws IOException {
|
||||
int bitsPerEntry = in.readByte();
|
||||
Palette palette = readPalette(paletteType, bitsPerEntry, in);
|
||||
BitStorage storage;
|
||||
if (!(palette instanceof SingletonPalette)) {
|
||||
int length = in.readVarInt();
|
||||
storage = new BitStorage(bitsPerEntry, paletteType.getStorageSize(), in.readLongs(length));
|
||||
} else {
|
||||
in.readVarInt();
|
||||
storage = null;
|
||||
}
|
||||
|
||||
return new DataPalette(palette, storage, paletteType, globalPaletteBits);
|
||||
}
|
||||
|
||||
public static void write(NetOutput out, DataPalette palette) throws IOException {
|
||||
if (palette.palette instanceof SingletonPalette) {
|
||||
out.writeByte(0); // Bits per entry
|
||||
out.writeVarInt(palette.palette.idToState(0));
|
||||
out.writeVarInt(0); // Data length
|
||||
return;
|
||||
}
|
||||
|
||||
out.writeByte(palette.storage.getBitsPerEntry());
|
||||
|
||||
if (!(palette.palette instanceof GlobalPalette)) {
|
||||
int paletteLength = palette.palette.size();
|
||||
out.writeVarInt(paletteLength);
|
||||
for (int i = 0; i < paletteLength; i++) {
|
||||
out.writeVarInt(palette.palette.idToState(i));
|
||||
}
|
||||
}
|
||||
|
||||
long[] data = palette.storage.getData();
|
||||
out.writeVarInt(data.length);
|
||||
out.writeLongs(data);
|
||||
}
|
||||
|
||||
public int get(int x, int y, int z) {
|
||||
if (storage != null) {
|
||||
int id = this.storage.get(index(x, y, z));
|
||||
return this.palette.idToState(id);
|
||||
} else {
|
||||
return this.palette.idToState(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the old value present in the storage.
|
||||
*/
|
||||
public int set(int x, int y, int z, int state) {
|
||||
int id = this.palette.stateToId(state);
|
||||
if (id == -1) {
|
||||
resize();
|
||||
id = this.palette.stateToId(state);
|
||||
}
|
||||
|
||||
if (this.storage != null) {
|
||||
int index = index(x, y, z);
|
||||
int curr = this.storage.get(index);
|
||||
|
||||
this.storage.set(index, id);
|
||||
return curr;
|
||||
} else {
|
||||
// Singleton palette and the block has not changed because the palette hasn't resized
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
private static Palette readPalette(PaletteType paletteType, int bitsPerEntry, NetInput in) throws IOException {
|
||||
if (bitsPerEntry > paletteType.getMaxBitsPerEntry()) {
|
||||
return new GlobalPalette();
|
||||
}
|
||||
if (bitsPerEntry == 0) {
|
||||
return new SingletonPalette(in);
|
||||
}
|
||||
if (bitsPerEntry <= paletteType.getMinBitsPerEntry()) {
|
||||
return new ListPalette(bitsPerEntry, in);
|
||||
} else {
|
||||
return new MapPalette(bitsPerEntry, in);
|
||||
}
|
||||
}
|
||||
|
||||
private int sanitizeBitsPerEntry(int bitsPerEntry) {
|
||||
if (bitsPerEntry <= this.paletteType.getMaxBitsPerEntry()) {
|
||||
return Math.max(this.paletteType.getMinBitsPerEntry(), bitsPerEntry);
|
||||
} else {
|
||||
return GLOBAL_PALETTE_BITS_PER_ENTRY;
|
||||
}
|
||||
}
|
||||
|
||||
private void resize() {
|
||||
Palette oldPalette = this.palette;
|
||||
BitStorage oldData = this.storage;
|
||||
|
||||
int bitsPerEntry = sanitizeBitsPerEntry(oldPalette instanceof SingletonPalette ? 1 : oldData.getBitsPerEntry() + 1);
|
||||
this.palette = createPalette(bitsPerEntry, paletteType);
|
||||
this.storage = new BitStorage(bitsPerEntry, paletteType.getStorageSize());
|
||||
|
||||
if (oldPalette instanceof SingletonPalette) {
|
||||
for (int i = 0; i < paletteType.getStorageSize(); i++) {
|
||||
// TODO necessary?
|
||||
this.storage.set(i, 0);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < paletteType.getStorageSize(); i++) {
|
||||
this.storage.set(i, this.palette.stateToId(oldPalette.idToState(oldData.get(i))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Palette createPalette(int bitsPerEntry, PaletteType paletteType) {
|
||||
if (bitsPerEntry <= paletteType.getMinBitsPerEntry()) {
|
||||
return new ListPalette(bitsPerEntry);
|
||||
} else if (bitsPerEntry <= paletteType.getMaxBitsPerEntry()) {
|
||||
return new MapPalette(bitsPerEntry);
|
||||
} else {
|
||||
return new GlobalPalette();
|
||||
}
|
||||
}
|
||||
|
||||
private static int index(int x, int y, int z) {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PaletteType {
|
||||
BIOME(1, 3, 64),
|
||||
CHUNK(4, 8, 4096);
|
||||
|
||||
private final int minBitsPerEntry;
|
||||
private final int maxBitsPerEntry;
|
||||
private final int storageSize;
|
||||
|
||||
PaletteType(int minBitsPerEntry, int maxBitsPerEntry, int storageSize) {
|
||||
this.minBitsPerEntry = minBitsPerEntry;
|
||||
this.maxBitsPerEntry = maxBitsPerEntry;
|
||||
this.storageSize = storageSize;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A palette containing one state.
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
public class SingletonPalette implements Palette {
|
||||
private final int state;
|
||||
|
||||
public SingletonPalette(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public SingletonPalette(NetInput in) throws IOException {
|
||||
this.state = in.readVarInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int stateToId(int state) {
|
||||
if (this.state == state) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int idToState(int id) {
|
||||
if (id == 0) {
|
||||
return this.state;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity;
|
||||
|
||||
public enum EntityStatus {
|
||||
public enum EntityEvent {
|
||||
TIPPED_ARROW_EMIT_PARTICLES,
|
||||
RABBIT_JUMP_OR_MINECART_SPAWNER_DELAY_RESET,
|
||||
LIVING_HURT,
|
|
@ -15,10 +15,10 @@ public class Attribute {
|
|||
private final @NonNull List<AttributeModifier> modifiers;
|
||||
|
||||
public Attribute(@NonNull AttributeType type) {
|
||||
this(type, type.getDef());
|
||||
this(type, 0);
|
||||
}
|
||||
|
||||
public Attribute(@NonNull AttributeType type, double value) {
|
||||
this(type, value, new ArrayList<AttributeModifier>());
|
||||
this(type, value, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +1,22 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.attribute;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.UnmappedValueException;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
public class AttributeModifier {
|
||||
private final ModifierType type;
|
||||
/**
|
||||
* Use {@link ModifierType} to determine built-in modifiers.
|
||||
*/
|
||||
private final @NonNull UUID uuid;
|
||||
private final double amount;
|
||||
private final @NonNull ModifierOperation operation;
|
||||
|
||||
public AttributeModifier(@NonNull ModifierType type, double amount, @NonNull ModifierOperation operation) {
|
||||
this.type = type;
|
||||
this.uuid = MagicValues.value(UUID.class, type);
|
||||
this.amount = amount;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public AttributeModifier(@NonNull UUID uuid, double amount, @NonNull ModifierOperation operation) {
|
||||
ModifierType type = null;
|
||||
try {
|
||||
type = MagicValues.key(ModifierType.class, uuid);
|
||||
} catch (UnmappedValueException e) {
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
this.uuid = uuid;
|
||||
this.amount = amount;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public Optional<ModifierType> getType() {
|
||||
return Optional.ofNullable(this.type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,75 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.attribute;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AttributeType {
|
||||
GENERIC_MAX_HEALTH(20, 0, 1024),
|
||||
GENERIC_FOLLOW_RANGE(32, 0, 2048),
|
||||
GENERIC_KNOCKBACK_RESISTANCE(0, 0, 1),
|
||||
GENERIC_MOVEMENT_SPEED(0.699999988079071, 0, 1024),
|
||||
GENERIC_ATTACK_DAMAGE(2, 0, 2048),
|
||||
GENERIC_ATTACK_SPEED(4, 0, 1024),
|
||||
GENERIC_FLYING_SPEED(0.4000000059604645, 0, 1024),
|
||||
GENERIC_ARMOR(0, 0, 30),
|
||||
GENERIC_ARMOR_TOUGHNESS(0, 0, 20),
|
||||
GENERIC_ATTACK_KNOCKBACK(0, 0, 5),
|
||||
GENERIC_LUCK(0, -1024, 1024),
|
||||
HORSE_JUMP_STRENGTH(0.7, 0, 2),
|
||||
ZOMBIE_SPAWN_REINFORCEMENTS(0, 0, 1),
|
||||
/**
|
||||
* Only available for clients/servers using Minecraft Forge.
|
||||
* Source: MinecraftForge/patches/minecraft/net/minecraft/entity/LivingEntity.java.patch#12
|
||||
*/
|
||||
ENTITY_GRAVITY(0.08, -8.0, 8.0);
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
private final double def;
|
||||
private final double min;
|
||||
private final double max;
|
||||
public interface AttributeType {
|
||||
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* Used when MCProtocolLib gets an attribute not in its built-in registry.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
class Custom implements AttributeType {
|
||||
private final String identifier;
|
||||
|
||||
public Custom(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
enum Builtin implements AttributeType {
|
||||
GENERIC_MAX_HEALTH("minecraft:generic.max_health", 20, 0, 1024),
|
||||
GENERIC_FOLLOW_RANGE("minecraft:generic.follow_range", 32, 0, 2048),
|
||||
GENERIC_KNOCKBACK_RESISTANCE("minecraft:generic.knockback_resistance", 0, 0, 1),
|
||||
GENERIC_MOVEMENT_SPEED("minecraft:generic.movement_speed", 0.699999988079071, 0, 1024),
|
||||
GENERIC_ATTACK_DAMAGE("minecraft:generic.attack_damage", 2, 0, 2048),
|
||||
GENERIC_ATTACK_SPEED("minecraft:generic.attack_speed", 4, 0, 1024),
|
||||
GENERIC_FLYING_SPEED("minecraft:generic.flying_speed", 0.4000000059604645, 0, 1024),
|
||||
GENERIC_ARMOR("minecraft:generic.armor", 0, 0, 30),
|
||||
GENERIC_ARMOR_TOUGHNESS("minecraft:generic.armor_toughness", 0, 0, 20),
|
||||
GENERIC_ATTACK_KNOCKBACK("minecraft:generic.attack_knockback", 0, 0, 5),
|
||||
GENERIC_LUCK("minecraft:generic.luck", 0, -1024, 1024),
|
||||
HORSE_JUMP_STRENGTH("minecraft:horse.jump_strength", 0.7, 0, 2),
|
||||
ZOMBIE_SPAWN_REINFORCEMENTS("minecraft:zombie.spawn_reinforcements", 0, 0, 1);
|
||||
|
||||
private final String identifier;
|
||||
private final double def;
|
||||
private final double min;
|
||||
private final double max;
|
||||
|
||||
public static final Map<String, AttributeType> BUILTIN = new HashMap<>();
|
||||
|
||||
static {
|
||||
register(GENERIC_MAX_HEALTH);
|
||||
register(GENERIC_FOLLOW_RANGE);
|
||||
register(GENERIC_KNOCKBACK_RESISTANCE);
|
||||
register(GENERIC_MOVEMENT_SPEED);
|
||||
register(GENERIC_ATTACK_DAMAGE);
|
||||
register(GENERIC_ATTACK_SPEED);
|
||||
register(GENERIC_FLYING_SPEED);
|
||||
register(GENERIC_ARMOR);
|
||||
register(GENERIC_ARMOR_TOUGHNESS);
|
||||
register(GENERIC_ATTACK_KNOCKBACK);
|
||||
register(GENERIC_LUCK);
|
||||
register(HORSE_JUMP_STRENGTH);
|
||||
register(ZOMBIE_SPAWN_REINFORCEMENTS);
|
||||
}
|
||||
|
||||
private static void register(AttributeType attributeType) {
|
||||
BUILTIN.put(attributeType.getIdentifier(), attributeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.attribute;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public enum ModifierOperation {
|
||||
ADD,
|
||||
ADD_MULTIPLIED,
|
||||
MULTIPLY;
|
||||
|
||||
private static final ModifierOperation[] VALUES = values();
|
||||
|
||||
public static ModifierOperation read(NetInput in) throws IOException {
|
||||
return VALUES[in.readByte()];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,28 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.attribute;
|
||||
|
||||
public enum ModifierType {
|
||||
CREATURE_FLEE_SPEED_BONUS,
|
||||
ENDERMAN_ATTACK_SPEED_BOOST,
|
||||
SPRINT_SPEED_BOOST,
|
||||
PIGZOMBIE_ATTACK_SPEED_BOOST,
|
||||
WITCH_DRINKING_SPEED_PENALTY,
|
||||
ZOMBIE_BABY_SPEED_BOOST,
|
||||
ATTACK_DAMAGE_MODIFIER,
|
||||
ATTACK_SPEED_MODIFIER,
|
||||
SPEED_POTION_MODIFIER,
|
||||
HEALTH_BOOST_POTION_MODIFIER,
|
||||
SLOW_POTION_MODIFIER,
|
||||
STRENGTH_POTION_MODIFIER,
|
||||
WEAKNESS_POTION_MODIFIER,
|
||||
HASTE_POTION_MODIFIER,
|
||||
MINING_FATIGUE_POTION_MODIFIER,
|
||||
LUCK_POTION_MODIFIER,
|
||||
UNLUCK_POTION_MODIFIER,
|
||||
BOOTS_MODIFIER,
|
||||
LEGGINGS_MODIFIER,
|
||||
CHESTPLATE_MODIFIER,
|
||||
HELMET_MODIFIER,
|
||||
COVERED_ARMOR_BONUS,
|
||||
/**
|
||||
* Only available for clients/servers using Minecraft Forge.
|
||||
* Source: MinecraftForge/patches/minecraft/net/minecraft/entity/LivingEntity.java.patch#9
|
||||
*/
|
||||
SLOW_FALLING
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ModifierType {
|
||||
public static final UUID CREATURE_FLEE_SPEED_BONUS = UUID.fromString("E199AD21-BA8A-4C53-8D13-6182D5C69D3A");
|
||||
public static final UUID ENDERMAN_ATTACK_SPEED_BOOST = UUID.fromString("020E0DFB-87AE-4653-9556-831010E291A0");
|
||||
public static final UUID SPRINT_SPEED_BOOST = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
|
||||
public static final UUID PIGZOMBIE_ATTACK_SPEED_BOOST = UUID.fromString("49455A49-7EC5-45BA-B886-3B90B23A1718");
|
||||
public static final UUID WITCH_DRINKING_SPEED_PENALTY = UUID.fromString("5CD17E52-A79A-43D3-A529-90FDE04B181E");
|
||||
public static final UUID ZOMBIE_BABY_SPEED_BOOST = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836");
|
||||
public static final UUID ATTACK_DAMAGE_MODIFIER = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF");
|
||||
public static final UUID ATTACK_SPEED_MODIFIER = UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3");
|
||||
public static final UUID SPEED_POTION_MODIFIER = UUID.fromString("91AEAA56-376B-4498-935B-2F7F68070635");
|
||||
public static final UUID HEALTH_BOOST_POTION_MODIFIER = UUID.fromString("5D6F0BA2-1186-46AC-B896-C61C5CEE99CC");
|
||||
public static final UUID SLOW_POTION_MODIFIER = UUID.fromString("7107DE5E-7CE8-4030-940E-514C1F160890");
|
||||
public static final UUID STRENGTH_POTION_MODIFIER = UUID.fromString("648D7064-6A60-4F59-8ABE-C2C23A6DD7A9");
|
||||
public static final UUID WEAKNESS_POTION_MODIFIER = UUID.fromString("22653B89-116E-49DC-9B6B-9971489B5BE5");
|
||||
public static final UUID HASTE_POTION_MODIFIER = UUID.fromString("AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3");
|
||||
public static final UUID MINING_FATIGUE_POTION_MODIFIER = UUID.fromString("55FCED67-E92A-486E-9800-B47F202C4386");
|
||||
public static final UUID LUCK_POTION_MODIFIER = UUID.fromString("03C3C89D-7037-4B42-869F-B146BCB64D2E");
|
||||
public static final UUID UNLUCK_POTION_MODIFIER = UUID.fromString("CC5AF142-2BD2-4215-B636-2605AED11727");
|
||||
public static final UUID BOOTS_MODIFIER = UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B");
|
||||
public static final UUID LEGGINGS_MODIFIER = UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D");
|
||||
public static final UUID CHESTPLATE_MODIFIER = UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E");
|
||||
public static final UUID HELMET_MODIFIER = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
||||
public static final UUID COVERED_ARMOR_BONUS = UUID.fromString("7E0292F2-9434-48D5-A29F-9583AF7DF27F");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BooleanMetadataType extends MetadataType<Boolean> {
|
||||
private final BooleanReader primitiveReader;
|
||||
private final BooleanWriter primitiveWriter;
|
||||
private final BooleanEntityMetadataFactory primitiveFactory;
|
||||
|
||||
protected BooleanMetadataType(BooleanReader reader, BooleanWriter writer, BooleanEntityMetadataFactory metadataFactory) {
|
||||
super(reader, writer, metadataFactory);
|
||||
|
||||
this.primitiveReader = reader;
|
||||
this.primitiveWriter = writer;
|
||||
this.primitiveFactory = metadataFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityMetadata<Boolean, BooleanMetadataType> readMetadata(NetInput input, int id) throws IOException {
|
||||
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
||||
}
|
||||
|
||||
public void writeMetadataPrimitive(NetOutput output, boolean value) throws IOException {
|
||||
this.primitiveWriter.writePrimitive(output, value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BooleanReader extends Reader<Boolean> {
|
||||
boolean readPrimitive(NetInput input) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default Boolean read(NetInput input) throws IOException {
|
||||
return this.readPrimitive(input);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BooleanWriter extends Writer<Boolean> {
|
||||
void writePrimitive(NetOutput output, boolean value) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default void write(NetOutput output, Boolean value) throws IOException {
|
||||
this.writePrimitive(output, value);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BooleanEntityMetadataFactory extends EntityMetadataFactory<Boolean> {
|
||||
BooleanEntityMetadata createPrimitive(int id, BooleanMetadataType type, boolean value);
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default EntityMetadata<Boolean, BooleanMetadataType> create(int id, MetadataType<Boolean> type, Boolean value) {
|
||||
throw new UnsupportedOperationException("Unsupported read method! Use primitive createPrimitive!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ByteMetadataType extends MetadataType<Byte> {
|
||||
private final ByteReader primitiveReader;
|
||||
private final ByteWriter primitiveWriter;
|
||||
private final ByteEntityMetadataFactory primitiveFactory;
|
||||
|
||||
protected ByteMetadataType(ByteReader reader, ByteWriter writer, ByteEntityMetadataFactory metadataFactory) {
|
||||
super(reader, writer, metadataFactory);
|
||||
|
||||
this.primitiveReader = reader;
|
||||
this.primitiveWriter = writer;
|
||||
this.primitiveFactory = metadataFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityMetadata<Byte, ByteMetadataType> readMetadata(NetInput input, int id) throws IOException {
|
||||
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
||||
}
|
||||
|
||||
public void writeMetadataPrimitive(NetOutput output, byte value) throws IOException {
|
||||
this.primitiveWriter.writePrimitive(output, value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ByteReader extends Reader<Byte> {
|
||||
byte readPrimitive(NetInput input) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default Byte read(NetInput input) throws IOException {
|
||||
return this.readPrimitive(input);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ByteWriter extends Writer<Byte> {
|
||||
void writePrimitive(NetOutput output, byte value) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default void write(NetOutput output, Byte value) throws IOException {
|
||||
this.writePrimitive(output, value);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ByteEntityMetadataFactory extends EntityMetadataFactory<Byte> {
|
||||
ByteEntityMetadata createPrimitive(int id, ByteMetadataType type, byte value);
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default EntityMetadata<Byte, ByteMetadataType> create(int id, MetadataType<Byte> type, Byte value) {
|
||||
throw new UnsupportedOperationException("Unsupported read method! Use primitive createPrimitive!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,205 +1,74 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.game.NBT;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.particle.Particle;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleData;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleType;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.*;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class EntityMetadata {
|
||||
private final int id;
|
||||
private final @NonNull MetadataType type;
|
||||
private final Object value;
|
||||
public abstract class EntityMetadata<V, T extends MetadataType<V>> {
|
||||
protected final int id;
|
||||
protected final @NonNull T type;
|
||||
|
||||
public static EntityMetadata[] read(NetInput in) throws IOException {
|
||||
List<EntityMetadata> ret = new ArrayList<EntityMetadata>();
|
||||
/**
|
||||
* May be null depending on type
|
||||
*/
|
||||
public abstract V getValue();
|
||||
|
||||
public static EntityMetadata<?, ?>[] read(NetInput in) throws IOException {
|
||||
List<EntityMetadata<?, ?>> ret = new ArrayList<>();
|
||||
int id;
|
||||
while ((id = in.readUnsignedByte()) != 255) {
|
||||
int typeId = in.readVarInt();
|
||||
MetadataType type = MagicValues.key(MetadataType.class, typeId);
|
||||
Object value = null;
|
||||
switch (type) {
|
||||
case BYTE:
|
||||
value = in.readByte();
|
||||
break;
|
||||
case INT:
|
||||
case BLOCK_STATE:
|
||||
value = in.readVarInt();
|
||||
break;
|
||||
case FLOAT:
|
||||
value = in.readFloat();
|
||||
break;
|
||||
case STRING:
|
||||
value = in.readString();
|
||||
break;
|
||||
case OPTIONAL_CHAT:
|
||||
boolean chatPresent = in.readBoolean();
|
||||
if (!chatPresent) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Intentional fall-through
|
||||
case CHAT:
|
||||
value = DefaultComponentSerializer.get().deserialize(in.readString());
|
||||
break;
|
||||
case ITEM:
|
||||
value = ItemStack.read(in);
|
||||
break;
|
||||
case BOOLEAN:
|
||||
value = in.readBoolean();
|
||||
break;
|
||||
case ROTATION:
|
||||
value = Rotation.read(in);
|
||||
break;
|
||||
case OPTIONAL_POSITION:
|
||||
boolean positionPresent = in.readBoolean();
|
||||
if (!positionPresent) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Intentional fall-through
|
||||
case POSITION:
|
||||
value = Position.read(in);
|
||||
break;
|
||||
case BLOCK_FACE:
|
||||
value = MagicValues.key(BlockFace.class, in.readVarInt());
|
||||
break;
|
||||
case OPTIONAL_UUID:
|
||||
boolean uuidPresent = in.readBoolean();
|
||||
if (uuidPresent) {
|
||||
value = in.readUUID();
|
||||
}
|
||||
|
||||
break;
|
||||
case NBT_TAG:
|
||||
value = NBT.read(in);
|
||||
break;
|
||||
case PARTICLE:
|
||||
ParticleType particleType = ParticleType.values()[in.readVarInt()];
|
||||
value = new Particle(particleType, ParticleData.read(in, particleType));
|
||||
break;
|
||||
case VILLAGER_DATA:
|
||||
value = new VillagerData(in.readVarInt(), in.readVarInt(), in.readVarInt());
|
||||
break;
|
||||
case OPTIONAL_VARINT:
|
||||
int i = in.readVarInt();
|
||||
value = i == 0 ? OptionalInt.empty() : OptionalInt.of(i - 1);
|
||||
break;
|
||||
case POSE:
|
||||
value = MagicValues.key(Pose.class, in.readVarInt());
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Unknown metadata type id: " + typeId);
|
||||
}
|
||||
|
||||
ret.add(new EntityMetadata(id, type, value));
|
||||
MetadataType<?> type = MetadataType.read(in);
|
||||
ret.add(type.readMetadata(in, id));
|
||||
}
|
||||
|
||||
return ret.toArray(new EntityMetadata[ret.size()]);
|
||||
return ret.toArray(new EntityMetadata[0]);
|
||||
}
|
||||
|
||||
public static void write(NetOutput out, EntityMetadata[] metadata) throws IOException {
|
||||
for (EntityMetadata meta : metadata) {
|
||||
/**
|
||||
* Overridden for primitive classes. This write method still checks for these primitives in the event
|
||||
* they are manually created using {@link ObjectEntityMetadata}.
|
||||
*/
|
||||
protected void write(NetOutput out) throws IOException {
|
||||
this.type.writeMetadata(out, this.getValue());
|
||||
}
|
||||
|
||||
public static void write(NetOutput out, EntityMetadata<?, ?>[] metadata) throws IOException {
|
||||
for (EntityMetadata<?, ?> meta : metadata) {
|
||||
out.writeByte(meta.getId());
|
||||
out.writeVarInt(MagicValues.value(Integer.class, meta.getType()));
|
||||
switch (meta.getType()) {
|
||||
case BYTE:
|
||||
out.writeByte((Byte) meta.getValue());
|
||||
break;
|
||||
case INT:
|
||||
out.writeVarInt((Integer) meta.getValue());
|
||||
break;
|
||||
case FLOAT:
|
||||
out.writeFloat((Float) meta.getValue());
|
||||
break;
|
||||
case STRING:
|
||||
out.writeString((String) meta.getValue());
|
||||
break;
|
||||
case OPTIONAL_CHAT:
|
||||
out.writeBoolean(meta.getValue() != null);
|
||||
if (meta.getValue() == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Intentional fall-through
|
||||
case CHAT:
|
||||
out.writeString(DefaultComponentSerializer.get().serialize((Component) meta.getValue()));
|
||||
break;
|
||||
case ITEM:
|
||||
ItemStack.write(out, (ItemStack) meta.getValue());
|
||||
break;
|
||||
case BOOLEAN:
|
||||
out.writeBoolean((Boolean) meta.getValue());
|
||||
break;
|
||||
case ROTATION:
|
||||
Rotation.write(out, (Rotation) meta.getValue());
|
||||
break;
|
||||
case OPTIONAL_POSITION:
|
||||
out.writeBoolean(meta.getValue() != null);
|
||||
if (meta.getValue() == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Intentional fall-through
|
||||
case POSITION:
|
||||
Position.write(out, (Position) meta.getValue());
|
||||
break;
|
||||
case BLOCK_FACE:
|
||||
out.writeVarInt(MagicValues.value(Integer.class, meta.getValue()));
|
||||
break;
|
||||
case OPTIONAL_UUID:
|
||||
out.writeBoolean(meta.getValue() != null);
|
||||
if (meta.getValue() != null) {
|
||||
out.writeUUID((UUID) meta.getValue());
|
||||
}
|
||||
|
||||
break;
|
||||
case BLOCK_STATE:
|
||||
out.writeVarInt((int) meta.getValue());
|
||||
break;
|
||||
case NBT_TAG:
|
||||
NBT.write(out, (CompoundTag) meta.getValue());
|
||||
break;
|
||||
case PARTICLE:
|
||||
Particle particle = (Particle) meta.getValue();
|
||||
out.writeVarInt(particle.getType().ordinal());
|
||||
ParticleData.write(out, particle.getType(), particle.getData());
|
||||
break;
|
||||
case VILLAGER_DATA:
|
||||
VillagerData villagerData = (VillagerData) meta.getValue();
|
||||
out.writeVarInt(villagerData.getType());
|
||||
out.writeVarInt(villagerData.getProfession());
|
||||
out.writeVarInt(villagerData.getLevel());
|
||||
break;
|
||||
case OPTIONAL_VARINT:
|
||||
OptionalInt optionalInt = (OptionalInt) meta.getValue();
|
||||
out.writeVarInt(optionalInt.orElse(-1) + 1);
|
||||
break;
|
||||
case POSE:
|
||||
out.writeVarInt(MagicValues.value(Integer.class, meta.getValue()));
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Unknown metadata type: " + meta.getType());
|
||||
}
|
||||
MetadataType.write(out, meta.getType());
|
||||
meta.write(out);
|
||||
}
|
||||
|
||||
out.writeByte(255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EntityMetadata(id=" + id + ", type=" + type + ", value=" + getValue().toString() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof EntityMetadata)) {
|
||||
return false;
|
||||
}
|
||||
EntityMetadata<?, ?> that = (EntityMetadata<?, ?>) o;
|
||||
return this.id == that.id && this.type == that.type && Objects.equals(this.getValue(), that.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, type, getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FloatMetadataType extends MetadataType<Float> {
|
||||
private final FloatReader primitiveReader;
|
||||
private final FloatWriter primitiveWriter;
|
||||
private final FloatEntityMetadataFactory primitiveFactory;
|
||||
|
||||
protected FloatMetadataType(FloatReader reader, FloatWriter writer, FloatEntityMetadataFactory metadataFactory) {
|
||||
super(reader, writer, metadataFactory);
|
||||
|
||||
this.primitiveReader = reader;
|
||||
this.primitiveWriter = writer;
|
||||
this.primitiveFactory = metadataFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityMetadata<Float, FloatMetadataType> readMetadata(NetInput input, int id) throws IOException {
|
||||
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
||||
}
|
||||
|
||||
public void writeMetadataPrimitive(NetOutput output, float value) throws IOException {
|
||||
this.primitiveWriter.writePrimitive(output, value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FloatReader extends Reader<Float> {
|
||||
float readPrimitive(NetInput input) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default Float read(NetInput input) throws IOException {
|
||||
return this.readPrimitive(input);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FloatWriter extends Writer<Float> {
|
||||
void writePrimitive(NetOutput output, float value) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default void write(NetOutput output, Float value) throws IOException {
|
||||
this.writePrimitive(output, value);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FloatEntityMetadataFactory extends EntityMetadataFactory<Float> {
|
||||
FloatEntityMetadata createPrimitive(int id, FloatMetadataType type, float value);
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default EntityMetadata<Float, FloatMetadataType> create(int id, MetadataType<Float> type, Float value) {
|
||||
throw new UnsupportedOperationException("Unsupported read method! Use primitive createPrimitive!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IntMetadataType extends MetadataType<Integer> {
|
||||
private final IntReader primitiveReader;
|
||||
private final IntWriter primitiveWriter;
|
||||
private final IntEntityMetadataFactory primitiveFactory;
|
||||
|
||||
protected IntMetadataType(IntReader reader, IntWriter writer, IntEntityMetadataFactory metadataFactory) {
|
||||
super(reader, writer, metadataFactory);
|
||||
|
||||
this.primitiveReader = reader;
|
||||
this.primitiveWriter = writer;
|
||||
this.primitiveFactory = metadataFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityMetadata<Integer, IntMetadataType> readMetadata(NetInput input, int id) throws IOException {
|
||||
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
||||
}
|
||||
|
||||
public void writeMetadataPrimitive(NetOutput output, int value) throws IOException {
|
||||
this.primitiveWriter.writePrimitive(output, value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IntReader extends Reader<Integer> {
|
||||
int readPrimitive(NetInput input) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default Integer read(NetInput input) throws IOException {
|
||||
return this.readPrimitive(input);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IntWriter extends Writer<Integer> {
|
||||
void writePrimitive(NetOutput output, int value) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default void write(NetOutput output, Integer value) throws IOException {
|
||||
this.writePrimitive(output, value);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IntEntityMetadataFactory extends EntityMetadataFactory<Integer> {
|
||||
IntEntityMetadata createPrimitive(int id, IntMetadataType type, int value);
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
default EntityMetadata<Integer, IntMetadataType> create(int id, MetadataType<Integer> type, Integer value) {
|
||||
throw new UnsupportedOperationException("Unsupported read method! Use primitive createPrimitive!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +1,118 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||
|
||||
public enum MetadataType {
|
||||
BYTE,
|
||||
INT,
|
||||
FLOAT,
|
||||
STRING,
|
||||
CHAT,
|
||||
OPTIONAL_CHAT,
|
||||
ITEM,
|
||||
BOOLEAN,
|
||||
ROTATION,
|
||||
POSITION,
|
||||
OPTIONAL_POSITION,
|
||||
BLOCK_FACE,
|
||||
OPTIONAL_UUID,
|
||||
BLOCK_STATE,
|
||||
NBT_TAG,
|
||||
PARTICLE,
|
||||
VILLAGER_DATA,
|
||||
OPTIONAL_VARINT,
|
||||
POSE;
|
||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||
import com.github.steveice10.mc.protocol.data.game.NBT;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.particle.Particle;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MetadataType<T> {
|
||||
private static final List<MetadataType<?>> VALUES = new ArrayList<>();
|
||||
|
||||
public static final ByteMetadataType BYTE = new ByteMetadataType(NetInput::readByte, NetOutput::writeByte, ByteEntityMetadata::new);
|
||||
public static final IntMetadataType INT = new IntMetadataType(NetInput::readVarInt, NetOutput::writeVarInt, IntEntityMetadata::new);
|
||||
public static final FloatMetadataType FLOAT = new FloatMetadataType(NetInput::readFloat, NetOutput::writeFloat, FloatEntityMetadata::new);
|
||||
public static final MetadataType<String> STRING = new MetadataType<>(NetInput::readString, NetOutput::writeString, ObjectEntityMetadata::new);
|
||||
public static final MetadataType<Component> CHAT = new MetadataType<>(in -> DefaultComponentSerializer.get().deserialize(in.readString()),
|
||||
(out, value) -> out.writeString(DefaultComponentSerializer.get().serialize(value)),
|
||||
ObjectEntityMetadata::new);
|
||||
public static final MetadataType<Optional<Component>> OPTIONAL_CHAT = new MetadataType<>(optionalReader(in -> DefaultComponentSerializer.get().deserialize(in.readString())),
|
||||
optionalWriter((out, value) -> out.writeString(DefaultComponentSerializer.get().serialize(value))),
|
||||
ObjectEntityMetadata::new);
|
||||
public static final MetadataType<ItemStack> ITEM = new MetadataType<>(ItemStack::read, ItemStack::write, ObjectEntityMetadata::new);
|
||||
public static final BooleanMetadataType BOOLEAN = new BooleanMetadataType(NetInput::readBoolean, NetOutput::writeBoolean, BooleanEntityMetadata::new);
|
||||
public static final MetadataType<Rotation> ROTATION = new MetadataType<>(Rotation::read, Rotation::write, ObjectEntityMetadata::new);
|
||||
public static final MetadataType<Position> POSITION = new MetadataType<>(Position::read, Position::write, ObjectEntityMetadata::new);
|
||||
public static final MetadataType<Optional<Position>> OPTIONAL_POSITION = new MetadataType<>(optionalReader(Position::read), optionalWriter(Position::write), ObjectEntityMetadata::new);
|
||||
public static final MetadataType<Direction> DIRECTION = new MetadataType<>(in -> in.readEnum(Direction.VALUES), NetOutput::writeEnum, ObjectEntityMetadata::new);
|
||||
public static final MetadataType<Optional<UUID>> OPTIONAL_UUID = new MetadataType<>(optionalReader(NetInput::readUUID), optionalWriter(NetOutput::writeUUID), ObjectEntityMetadata::new);
|
||||
public static final IntMetadataType BLOCK_STATE = new IntMetadataType(NetInput::readVarInt, NetOutput::writeVarInt, IntEntityMetadata::new);
|
||||
public static final MetadataType<CompoundTag> NBT_TAG = new MetadataType<>(NBT::read, NBT::write, ObjectEntityMetadata::new);
|
||||
public static final MetadataType<Particle> PARTICLE = new MetadataType<>(Particle::read, Particle::write, ObjectEntityMetadata::new);
|
||||
public static final MetadataType<VillagerData> VILLAGER_DATA = new MetadataType<>(VillagerData::read, VillagerData::write, ObjectEntityMetadata::new);
|
||||
public static final OptionalIntMetadataType OPTIONAL_VARINT = new OptionalIntMetadataType(ObjectEntityMetadata::new);
|
||||
public static final MetadataType<Pose> POSE = new MetadataType<>(in -> in.readEnum(Pose.VALUES), NetOutput::writeEnum, ObjectEntityMetadata::new);
|
||||
|
||||
protected final int id;
|
||||
protected final Reader<T> reader;
|
||||
protected final Writer<T> writer;
|
||||
protected final EntityMetadataFactory<T> metadataFactory;
|
||||
|
||||
protected MetadataType(Reader<T> reader, Writer<T> writer, EntityMetadataFactory<T> metadataFactory) {
|
||||
this.id = VALUES.size();
|
||||
this.reader = reader;
|
||||
this.writer = writer;
|
||||
this.metadataFactory = metadataFactory;
|
||||
|
||||
VALUES.add(this);
|
||||
}
|
||||
|
||||
public EntityMetadata<T, ? extends MetadataType<T>> readMetadata(NetInput input, int id) throws IOException {
|
||||
return this.metadataFactory.create(id, this, this.reader.read(input));
|
||||
}
|
||||
|
||||
public void writeMetadata(NetOutput output, T value) throws IOException {
|
||||
this.writer.write(output, value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Reader<V> {
|
||||
V read(NetInput input) throws IOException;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Writer<V> {
|
||||
void write(NetOutput output, V value) throws IOException;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EntityMetadataFactory<V> {
|
||||
EntityMetadata<V, ? extends MetadataType<V>> create(int id, MetadataType<V> type, V value);
|
||||
}
|
||||
|
||||
private static <T> Reader<Optional<T>> optionalReader(Reader<T> reader) {
|
||||
return input -> {
|
||||
if (!input.readBoolean()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(reader.read(input));
|
||||
};
|
||||
}
|
||||
|
||||
private static <T> Writer<Optional<T>> optionalWriter(Writer<T> writer) {
|
||||
return (ouput, value) -> {
|
||||
ouput.writeBoolean(value.isPresent());
|
||||
if (value.isPresent()) {
|
||||
writer.write(ouput, value.get());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static MetadataType<?> read(NetInput in) throws IOException {
|
||||
int id = in.readVarInt();
|
||||
if (id >= VALUES.size()) {
|
||||
throw new IllegalArgumentException("Received id " + id + " for MetadataType when the maximum was " + VALUES.size() + "!");
|
||||
}
|
||||
|
||||
return VALUES.get(id);
|
||||
}
|
||||
|
||||
public static void write(NetOutput out, MetadataType<?> type) throws IOException {
|
||||
out.writeVarInt(type.id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class OptionalIntMetadataType extends MetadataType<OptionalInt> {
|
||||
protected OptionalIntMetadataType(EntityMetadataFactory<OptionalInt> metadataFactory) {
|
||||
super(OptionalIntReader.INSTANCE, OptionalIntWriter.INSTANCE, metadataFactory);
|
||||
}
|
||||
|
||||
public static class OptionalIntReader implements Reader<OptionalInt> {
|
||||
protected static final OptionalIntReader INSTANCE = new OptionalIntReader();
|
||||
|
||||
@Override
|
||||
public OptionalInt read(NetInput input) throws IOException {
|
||||
int value = input.readVarInt();
|
||||
if (value == 0) {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
return OptionalInt.of(value - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static class OptionalIntWriter implements Writer<OptionalInt> {
|
||||
protected static final OptionalIntWriter INSTANCE = new OptionalIntWriter();
|
||||
|
||||
@Override
|
||||
public void write(NetOutput output, OptionalInt value) throws IOException {
|
||||
if (value.isPresent()) {
|
||||
output.writeVarInt(value.getAsInt() + 1);
|
||||
} else {
|
||||
output.writeVarInt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,4 +9,6 @@ public enum Pose {
|
|||
SNEAKING,
|
||||
LONG_JUMPING,
|
||||
DYING;
|
||||
|
||||
public static final Pose[] VALUES = values();
|
||||
}
|
||||
|
|
|
@ -1,12 +1,26 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class VillagerData {
|
||||
private final int type;
|
||||
private final int profession;
|
||||
private final int level;
|
||||
|
||||
public static VillagerData read(NetInput in) throws IOException {
|
||||
return new VillagerData(in.readVarInt(), in.readVarInt(), in.readVarInt());
|
||||
}
|
||||
|
||||
public static void write(NetOutput out, VillagerData villagerData) throws IOException {
|
||||
out.writeVarInt(villagerData.getType());
|
||||
out.writeVarInt(villagerData.getProfession());
|
||||
out.writeVarInt(villagerData.getLevel());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.BooleanMetadataType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BooleanEntityMetadata extends EntityMetadata<Boolean, BooleanMetadataType> {
|
||||
private final boolean value;
|
||||
|
||||
public BooleanEntityMetadata(int id, @NonNull BooleanMetadataType type, boolean value) {
|
||||
super(id, type);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean getPrimitiveValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Boolean getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(NetOutput out) throws IOException {
|
||||
this.type.writeMetadataPrimitive(out, this.value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ByteMetadataType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ByteEntityMetadata extends EntityMetadata<Byte, ByteMetadataType> {
|
||||
private final byte value;
|
||||
|
||||
public ByteEntityMetadata(int id, @NonNull ByteMetadataType type, byte value) {
|
||||
super(id, type);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public byte getPrimitiveValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Byte getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(NetOutput out) throws IOException {
|
||||
this.type.writeMetadataPrimitive(out, this.value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.FloatMetadataType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FloatEntityMetadata extends EntityMetadata<Float, FloatMetadataType> {
|
||||
private final float value;
|
||||
|
||||
public FloatEntityMetadata(int id, @NonNull FloatMetadataType type, float value) {
|
||||
super(id, type);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public float getPrimitiveValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Float getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(NetOutput out) throws IOException {
|
||||
this.type.writeMetadataPrimitive(out, this.value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.IntMetadataType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Used for both {@link MetadataType#INT} and {@link MetadataType#BLOCK_STATE}.
|
||||
*/
|
||||
public class IntEntityMetadata extends EntityMetadata<Integer, IntMetadataType> {
|
||||
private final int value;
|
||||
|
||||
public IntEntityMetadata(int id, @NonNull IntMetadataType type, int value) {
|
||||
super(id, type);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getPrimitiveValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(NetOutput out) throws IOException {
|
||||
this.type.writeMetadataPrimitive(out, value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
||||
import lombok.NonNull;
|
||||
|
||||
public class ObjectEntityMetadata<T> extends EntityMetadata<T, MetadataType<T>> {
|
||||
private final T value;
|
||||
|
||||
public ObjectEntityMetadata(int id, @NonNull MetadataType<T> type, T value) {
|
||||
super(id, type);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.object;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum Direction implements ObjectData {
|
||||
DOWN(-1),
|
||||
UP(-1),
|
||||
NORTH(0),
|
||||
SOUTH(1),
|
||||
WEST(2),
|
||||
EAST(3);
|
||||
|
||||
@Getter
|
||||
private final int horizontalIndex;
|
||||
|
||||
Direction(int horizontalIndex) {
|
||||
this.horizontalIndex = horizontalIndex;
|
||||
}
|
||||
|
||||
private static final Direction[] HORIZONTAL_VALUES = {NORTH, SOUTH, WEST, EAST};
|
||||
public static final Direction[] VALUES = values();
|
||||
|
||||
public static Direction getByHorizontalIndex(int index) {
|
||||
return HORIZONTAL_VALUES[index % HORIZONTAL_VALUES.length];
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.object;
|
||||
|
||||
public enum HangingDirection implements ObjectData {
|
||||
DOWN,
|
||||
UP,
|
||||
NORTH,
|
||||
SOUTH,
|
||||
WEST,
|
||||
EAST;
|
||||
}
|
|
@ -4,7 +4,7 @@ public enum Animation {
|
|||
SWING_ARM,
|
||||
DAMAGE,
|
||||
LEAVE_BED,
|
||||
EAT_FOOD,
|
||||
SWING_OFFHAND,
|
||||
CRITICAL_HIT,
|
||||
ENCHANTMENT_CRITICAL_HIT;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.player;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public enum BlockBreakStage {
|
||||
STAGE_1,
|
||||
STAGE_2,
|
||||
|
@ -12,4 +16,23 @@ public enum BlockBreakStage {
|
|||
STAGE_9,
|
||||
STAGE_10,
|
||||
RESET;
|
||||
|
||||
/**
|
||||
* All stages, excluding reset
|
||||
*/
|
||||
public static final BlockBreakStage[] STAGES;
|
||||
|
||||
static {
|
||||
BlockBreakStage[] allValues = values();
|
||||
STAGES = new BlockBreakStage[allValues.length - 1];
|
||||
System.arraycopy(allValues, 0, STAGES, 0, 10);
|
||||
}
|
||||
|
||||
public void write(NetOutput out) throws IOException {
|
||||
if (this == RESET) {
|
||||
out.writeByte(255);
|
||||
} else {
|
||||
out.writeByte(ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.player;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.world.notify.ClientNotificationValue;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEventValue;
|
||||
|
||||
public enum GameMode implements ClientNotificationValue {
|
||||
public enum GameMode implements GameEventValue {
|
||||
SURVIVAL,
|
||||
CREATIVE,
|
||||
ADVENTURE,
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.type;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public enum EntityType {
|
||||
AREA_EFFECT_CLOUD,
|
||||
ARMOR_STAND,
|
||||
|
@ -7,16 +11,16 @@ public enum EntityType {
|
|||
AXOLOTL,
|
||||
BAT,
|
||||
BEE,
|
||||
BOAT,
|
||||
BLAZE,
|
||||
BOAT,
|
||||
CAT,
|
||||
CAVE_SPIDER,
|
||||
CHICKEN,
|
||||
COD,
|
||||
COW,
|
||||
CREEPER,
|
||||
DONKEY,
|
||||
DOLPHIN,
|
||||
DONKEY,
|
||||
DRAGON_FIREBALL,
|
||||
DROWNED,
|
||||
ELDER_GUARDIAN,
|
||||
|
@ -24,22 +28,24 @@ public enum EntityType {
|
|||
ENDER_DRAGON,
|
||||
ENDERMAN,
|
||||
ENDERMITE,
|
||||
EVOKER_FANGS,
|
||||
EVOKER,
|
||||
EVOKER_FANGS,
|
||||
EXPERIENCE_ORB,
|
||||
EYE_OF_ENDER,
|
||||
FALLING_BLOCK,
|
||||
FIREWORK_ROCKET,
|
||||
FOX,
|
||||
GOAT,
|
||||
GHAST,
|
||||
GIANT,
|
||||
GLOW_ITEM_FRAME,
|
||||
GLOW_SQUID,
|
||||
GOAT,
|
||||
GUARDIAN,
|
||||
HOGLIN,
|
||||
HORSE,
|
||||
HUSK,
|
||||
ILLUSIONER,
|
||||
IRON_GOLEM,
|
||||
ITEM,
|
||||
ITEM_FRAME,
|
||||
FIREBALL,
|
||||
|
@ -50,25 +56,28 @@ public enum EntityType {
|
|||
MAGMA_CUBE,
|
||||
MARKER,
|
||||
MINECART,
|
||||
MINECART_CHEST,
|
||||
MINECART_COMMAND_BLOCK,
|
||||
MINECART_FURNACE,
|
||||
MINECART_HOPPER,
|
||||
MINECART_SPAWNER,
|
||||
MINECART_TNT,
|
||||
CHEST_MINECART,
|
||||
COMMAND_BLOCK_MINECART,
|
||||
FURNACE_MINECART,
|
||||
HOPPER_MINECART,
|
||||
SPAWNER_MINECART,
|
||||
TNT_MINECART,
|
||||
MULE,
|
||||
MOOSHROOM,
|
||||
OCELOT,
|
||||
PAINTING,
|
||||
PANDA,
|
||||
PARROT,
|
||||
PHANTOM,
|
||||
PIG,
|
||||
PIGLIN,
|
||||
PIGLIN_BRUTE,
|
||||
PUFFERFISH,
|
||||
PILLAGER,
|
||||
POLAR_BEAR,
|
||||
PRIMED_TNT,
|
||||
TNT,
|
||||
PUFFERFISH,
|
||||
RABBIT,
|
||||
RAVAGER,
|
||||
SALMON,
|
||||
SHEEP,
|
||||
SHULKER,
|
||||
|
@ -84,34 +93,35 @@ public enum EntityType {
|
|||
SPIDER,
|
||||
SQUID,
|
||||
STRAY,
|
||||
STRIDER,
|
||||
EGG,
|
||||
ENDER_PEARL,
|
||||
EXPERIENCE_BOTTLE,
|
||||
POTION,
|
||||
TRIDENT,
|
||||
TRADER_LLAMA,
|
||||
TROPICAL_FISH,
|
||||
TURTLE,
|
||||
THROWN_EGG,
|
||||
THROWN_ENDERPEARL,
|
||||
THROWN_EXP_BOTTLE,
|
||||
THROWN_POTION,
|
||||
TRIDENT,
|
||||
VEX,
|
||||
VILLAGER,
|
||||
IRON_GOLEM,
|
||||
VINDICATOR,
|
||||
PILLAGER,
|
||||
WANDERING_TRADER,
|
||||
WITCH,
|
||||
WITHER,
|
||||
WITHER_SKELETON,
|
||||
WITHER_SKULL,
|
||||
WOLF,
|
||||
ZOGLIN,
|
||||
ZOMBIE,
|
||||
ZOMBIE_HORSE,
|
||||
ZOMBIFIED_PIGLIN,
|
||||
ZOMBIE_VILLAGER,
|
||||
PHANTOM,
|
||||
RAVAGER,
|
||||
HOGLIN,
|
||||
STRIDER,
|
||||
ZOGLIN,
|
||||
ZOMBIFIED_PIGLIN,
|
||||
PLAYER,
|
||||
FISHING_BOBBER;
|
||||
|
||||
private static final EntityType[] VALUES = values();
|
||||
|
||||
public static EntityType read(NetInput in) throws IOException {
|
||||
return in.readEnum(VALUES);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.entity.type;
|
||||
|
||||
public enum WeatherEntityType {
|
||||
LIGHTNING_BOLT;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum AdvancementTabAction {
|
||||
OPENED_TAB,
|
|
@ -0,0 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum ClickItemAction implements ContainerAction {
|
||||
LEFT_CLICK,
|
||||
RIGHT_CLICK;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public interface ContainerAction {
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum WindowAction {
|
||||
public enum ContainerActionType {
|
||||
CLICK_ITEM,
|
||||
SHIFT_CLICK_ITEM,
|
||||
MOVE_TO_HOTBAR_SLOT,
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum WindowType {
|
||||
public enum ContainerType {
|
||||
GENERIC_9X1,
|
||||
GENERIC_9X2,
|
||||
GENERIC_9X3,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum CraftingBookStateType {
|
||||
CRAFTING,
|
|
@ -0,0 +1,5 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum CreativeGrabAction implements ContainerAction {
|
||||
GRAB;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum DropItemParam implements WindowActionParam {
|
||||
public enum DropItemAction implements ContainerAction {
|
||||
DROP_FROM_SELECTED,
|
||||
DROP_SELECTED_STACK,
|
||||
LEFT_CLICK_OUTSIDE_NOT_HOLDING,
|
|
@ -0,0 +1,5 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum FillStackAction implements ContainerAction {
|
||||
FILL;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum MoveToHotbarAction implements ContainerAction {
|
||||
SLOT_1,
|
||||
SLOT_2,
|
||||
SLOT_3,
|
||||
SLOT_4,
|
||||
SLOT_5,
|
||||
SLOT_6,
|
||||
SLOT_7,
|
||||
SLOT_8,
|
||||
SLOT_9;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum ShiftClickItemAction implements ContainerAction {
|
||||
LEFT_CLICK,
|
||||
RIGHT_CLICK;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum SpreadItemParam implements WindowActionParam {
|
||||
public enum SpreadItemAction implements ContainerAction {
|
||||
LEFT_MOUSE_BEGIN_DRAG,
|
||||
LEFT_MOUSE_ADD_SLOT,
|
||||
LEFT_MOUSE_END_DRAG,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum UpdateStructureBlockAction {
|
||||
UPDATE_DATA,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
public enum UpdateStructureBlockMode {
|
||||
SAVE,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import lombok.AllArgsConstructor;
|
|
@ -1,7 +1,7 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window.property;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory.property;
|
||||
|
||||
/**
|
||||
* Window properties of an anvil.
|
||||
* Container properties of an anvil.
|
||||
*/
|
||||
public enum AnvilProperty {
|
||||
/**
|
|
@ -0,0 +1,12 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.inventory.property;
|
||||
|
||||
/**
|
||||
* Container properties of a brewing stand.
|
||||
*/
|
||||
public enum BrewingStandProperty implements ContainerProperty {
|
||||
/**
|
||||
* Time remaining for potions to finish brewing.
|
||||
* Usually a value between 0 (done) and 400 (just started).
|
||||
*/
|
||||
BREW_TIME,
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.inventory.property;
|
||||
|
||||
public interface ContainerProperty {
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window.property;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory.property;
|
||||
|
||||
/**
|
||||
* Window properties of an enchantment table.
|
||||
* Container properties of an enchantment table.
|
||||
*/
|
||||
public enum EnchantmentTableProperty implements WindowProperty {
|
||||
public enum EnchantmentTableProperty implements ContainerProperty {
|
||||
/**
|
||||
* Level of the enchantment in slot 1.
|
||||
*/
|
|
@ -1,7 +1,7 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window.property;
|
||||
package com.github.steveice10.mc.protocol.data.game.inventory.property;
|
||||
|
||||
/**
|
||||
* Window properties of a furnace.
|
||||
* Container properties of a furnace.
|
||||
*/
|
||||
public enum FurnaceProperty {
|
||||
/**
|
|
@ -0,0 +1,82 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class LightUpdateData {
|
||||
private final @NonNull BitSet skyYMask;
|
||||
private final @NonNull BitSet blockYMask;
|
||||
private final @NonNull BitSet emptySkyYMask;
|
||||
private final @NonNull BitSet emptyBlockYMask;
|
||||
private final @NonNull List<byte[]> skyUpdates;
|
||||
private final @NonNull List<byte[]> blockUpdates;
|
||||
private final boolean trustEdges;
|
||||
|
||||
public static LightUpdateData read(NetInput in) throws IOException {
|
||||
return new LightUpdateData(in);
|
||||
}
|
||||
|
||||
private LightUpdateData(NetInput in) throws IOException {
|
||||
this.trustEdges = in.readBoolean();
|
||||
|
||||
this.skyYMask = BitSet.valueOf(in.readLongs(in.readVarInt()));
|
||||
this.blockYMask = BitSet.valueOf(in.readLongs(in.readVarInt()));
|
||||
this.emptySkyYMask = BitSet.valueOf(in.readLongs(in.readVarInt()));
|
||||
this.emptyBlockYMask = BitSet.valueOf(in.readLongs(in.readVarInt()));
|
||||
|
||||
int skyUpdateSize = in.readVarInt();
|
||||
skyUpdates = new ArrayList<>(skyUpdateSize);
|
||||
for (int i = 0; i < skyUpdateSize; i++) {
|
||||
skyUpdates.add(in.readBytes(in.readVarInt()));
|
||||
}
|
||||
|
||||
int blockUpdateSize = in.readVarInt();
|
||||
blockUpdates = new ArrayList<>(blockUpdateSize);
|
||||
for (int i = 0; i < blockUpdateSize; i++) {
|
||||
blockUpdates.add(in.readBytes(in.readVarInt()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(NetOutput out, LightUpdateData data) throws IOException {
|
||||
data.write(out);
|
||||
}
|
||||
|
||||
private void write(NetOutput out) throws IOException {
|
||||
out.writeBoolean(this.trustEdges);
|
||||
|
||||
writeBitSet(out, this.skyYMask);
|
||||
writeBitSet(out, this.blockYMask);
|
||||
writeBitSet(out, this.emptySkyYMask);
|
||||
writeBitSet(out, this.emptyBlockYMask);
|
||||
|
||||
out.writeVarInt(this.skyUpdates.size());
|
||||
for (byte[] array : this.skyUpdates) {
|
||||
out.writeVarInt(array.length);
|
||||
out.writeBytes(array);
|
||||
}
|
||||
|
||||
out.writeVarInt(this.blockUpdates.size());
|
||||
for (byte[] array : this.blockUpdates) {
|
||||
out.writeVarInt(array.length);
|
||||
out.writeBytes(array);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeBitSet(NetOutput out, BitSet bitSet) throws IOException {
|
||||
long[] array = bitSet.toLongArray();
|
||||
out.writeVarInt(array.length);
|
||||
for (long content : array) {
|
||||
out.writeLong(content);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -7,7 +7,7 @@ import lombok.NonNull;
|
|||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BlockChangeRecord {
|
||||
public class BlockChangeEntry {
|
||||
private final @NonNull Position position;
|
||||
private final @NonNull int block;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.block;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BlockEntityInfo {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final BlockEntityType type;
|
||||
private final @Nullable CompoundTag nbt;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.block;
|
||||
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
public enum BlockEntityType {
|
||||
FURNACE,
|
||||
CHEST,
|
||||
TRAPPED_CHEST,
|
||||
ENDER_CHEST,
|
||||
JUKEBOX,
|
||||
DISPENSER,
|
||||
DROPPER,
|
||||
SIGN,
|
||||
MOB_SPAWNER,
|
||||
PISTON,
|
||||
BREWING_STAND,
|
||||
ENCHANTING_TABLE,
|
||||
END_PORTAL,
|
||||
BEACON,
|
||||
SKULL,
|
||||
DAYLIGHT_DETECTOR,
|
||||
HOPPER,
|
||||
COMPARATOR,
|
||||
BANNER,
|
||||
STRUCTURE_BLOCK,
|
||||
END_GATEWAY,
|
||||
COMMAND_BLOCK,
|
||||
SHULKER_BOX,
|
||||
BED,
|
||||
CONDUIT,
|
||||
BARREL,
|
||||
SMOKER,
|
||||
BLAST_FURNACE,
|
||||
LECTERN,
|
||||
BELL,
|
||||
JIGSAW,
|
||||
CAMPFIRE,
|
||||
BEEHIVE,
|
||||
SCULK_SENSOR;
|
||||
|
||||
public static final BlockEntityType[] VALUES = values();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block;
|
||||
|
||||
public enum CommandBlockMode {
|
||||
SEQUENCE,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block;
|
||||
|
||||
public enum StructureMirror {
|
||||
NONE,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block;
|
||||
|
||||
public enum StructureRotation {
|
||||
NONE,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public enum BeaconValueType implements BlockValueType {
|
||||
RECALCULATE_BEAM;
|
|
@ -0,0 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public interface BlockValue {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public interface BlockValueType {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public enum ChestValueType implements BlockValueType {
|
||||
VIEWING_PLAYER_COUNT;
|
|
@ -0,0 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public class EndGatewayValue implements BlockValue {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public enum EndGatewayValueType implements BlockValueType {
|
||||
TRIGGER_BEAM;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public enum GenericBlockValueType implements BlockValueType {
|
||||
GENERIC_0,
|
|
@ -0,0 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public class MobSpawnerValue implements BlockValue {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public enum MobSpawnerValueType implements BlockValueType {
|
||||
RESET_DELAY;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
import lombok.Data;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public enum NoteBlockValueType implements BlockValueType {
|
||||
HARP,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public enum PistonValue implements BlockValue {
|
||||
DOWN,
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.block.value;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.block.value;
|
||||
|
||||
public enum PistonValueType implements BlockValueType {
|
||||
PUSHING,
|
|
@ -0,0 +1,10 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BonemealGrowEventData implements LevelEventData {
|
||||
private final int particleCount;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.effect;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -6,6 +6,6 @@ import lombok.NonNull;
|
|||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BreakBlockEffectData implements WorldEffectData {
|
||||
public class BreakBlockEventData implements LevelEventData {
|
||||
private final @NonNull int blockState;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BreakPotionEventData implements LevelEventData {
|
||||
private final int potionId;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
public enum ComposterEventData implements LevelEventData {
|
||||
FILL,
|
||||
FILL_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
public enum DragonFireballEventData implements LevelEventData {
|
||||
NO_SOUND,
|
||||
HAS_SOUND;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
public interface LevelEvent {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
public interface LevelEventData {
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.world.effect;
|
||||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
public enum ParticleEffect implements WorldEffect {
|
||||
public enum ParticleEvent implements LevelEvent {
|
||||
COMPOSTER,
|
||||
BLOCK_LAVA_EXTINGUISH,
|
||||
BLOCK_REDSTONE_TORCH_BURNOUT,
|
|
@ -0,0 +1,10 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class RecordEventData implements LevelEventData {
|
||||
private final int recordId;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue