mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-10 16:01:50 -04:00
support for rain, PacketChangeGameState, gamemode change support
This commit is contained in:
parent
e99741e6af
commit
9ea8f950bf
@ -12,6 +12,7 @@ public class World {
|
|||||||
public final HashMap<ChunkLocation, Chunk> chunks;
|
public final HashMap<ChunkLocation, Chunk> chunks;
|
||||||
final String name;
|
final String name;
|
||||||
boolean hardcore;
|
boolean hardcore;
|
||||||
|
boolean raining;
|
||||||
|
|
||||||
public World(String name) {
|
public World(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -65,4 +66,12 @@ public class World {
|
|||||||
public void setHardcore(boolean hardcore) {
|
public void setHardcore(boolean hardcore) {
|
||||||
this.hardcore = hardcore;
|
this.hardcore = hardcore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRaining() {
|
||||||
|
return raining;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRaining(boolean raining) {
|
||||||
|
this.raining = raining;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.game.datatypes.GameMode;
|
||||||
|
import de.bixilon.minosoft.logging.Log;
|
||||||
|
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
|
public class PacketChangeGameState implements ClientboundPacket {
|
||||||
|
Reason reason;
|
||||||
|
float value;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(InPacketBuffer buffer, ProtocolVersion v) {
|
||||||
|
switch (v) {
|
||||||
|
case VERSION_1_7_10:
|
||||||
|
reason = Reason.byId(buffer.readByte());
|
||||||
|
value = buffer.readFloat();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
log();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log() {
|
||||||
|
switch (getReason()) {
|
||||||
|
case START_RAIN:
|
||||||
|
Log.game("Received weather packet: Starting rain...");
|
||||||
|
break;
|
||||||
|
case END_RAIN:
|
||||||
|
Log.game("Received weather packet: Stopping rain...");
|
||||||
|
break;
|
||||||
|
case CHANGE_GAMEMODE:
|
||||||
|
Log.game(String.format("Received game mode change: Now in %s", GameMode.byId(getValue().intValue()).name()));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log.protocol(String.format("Received game status change (%s)", getReason().name()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(PacketHandler h) {
|
||||||
|
h.handle(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reason getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Reason {
|
||||||
|
INVALID_BED(0),
|
||||||
|
END_RAIN(1),
|
||||||
|
START_RAIN(2),
|
||||||
|
CHANGE_GAMEMODE(3),
|
||||||
|
ENTER_CREDITS(4),
|
||||||
|
DEMO_MESSAGES(5),
|
||||||
|
ARROW_HITTING_PLAYER(6),
|
||||||
|
FADE_VALUE(7),
|
||||||
|
FADE_TIME(8);
|
||||||
|
|
||||||
|
byte id;
|
||||||
|
|
||||||
|
Reason(byte id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
Reason(int id) {
|
||||||
|
this.id = (byte) id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Reason byId(byte id) {
|
||||||
|
for (Reason g : values()) {
|
||||||
|
if (g.getId() == id) {
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package de.bixilon.minosoft.protocol.protocol;
|
|||||||
|
|
||||||
import de.bixilon.minosoft.Minosoft;
|
import de.bixilon.minosoft.Minosoft;
|
||||||
import de.bixilon.minosoft.config.GameConfiguration;
|
import de.bixilon.minosoft.config.GameConfiguration;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.GameMode;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.network.Connection;
|
import de.bixilon.minosoft.protocol.network.Connection;
|
||||||
import de.bixilon.minosoft.protocol.packets.clientbound.login.PacketEncryptionKeyRequest;
|
import de.bixilon.minosoft.protocol.packets.clientbound.login.PacketEncryptionKeyRequest;
|
||||||
@ -113,4 +114,19 @@ public class PacketHandler {
|
|||||||
connection.getPlayer().setLevel(pkg.getLevel());
|
connection.getPlayer().setLevel(pkg.getLevel());
|
||||||
connection.getPlayer().setTotalExperience(pkg.getTotal());
|
connection.getPlayer().setTotalExperience(pkg.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handle(PacketChangeGameState pkg) {
|
||||||
|
switch (pkg.getReason()) {
|
||||||
|
case START_RAIN:
|
||||||
|
connection.getPlayer().getWorld().setRaining(true);
|
||||||
|
break;
|
||||||
|
case END_RAIN:
|
||||||
|
connection.getPlayer().getWorld().setRaining(false);
|
||||||
|
break;
|
||||||
|
case CHANGE_GAMEMODE:
|
||||||
|
connection.getPlayer().setGameMode(GameMode.byId(pkg.getValue().intValue()));
|
||||||
|
break;
|
||||||
|
//ToDo: handle all updates
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,5 +48,6 @@ public interface Protocol {
|
|||||||
packetClassMapping.put(Packets.Clientbound.PLAY_DISCONNECT, PacketDisconnect.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_DISCONNECT, PacketDisconnect.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_HELD_ITEM_CHANGE, PacketHeldItemChangeReceiving.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_HELD_ITEM_CHANGE, PacketHeldItemChangeReceiving.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_SET_EXPERIENCE, PacketSetExperience.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_SET_EXPERIENCE, PacketSetExperience.class);
|
||||||
|
packetClassMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, PacketChangeGameState.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user