Compare commits
1 Commits
dev/timeup
...
dev/experi
| Author | SHA1 | Date | |
|---|---|---|---|
|
346d64aea5
|
@@ -60,8 +60,8 @@ public enum State {
|
||||
JoinGamePacket.class, 0x23,
|
||||
PlayerAbilitiesPacket.class,0x2C,
|
||||
SPlayerPositionAndLookPacket.class, 0x2F,
|
||||
SpawnPositionPacket.class, 0x46,
|
||||
TimeUpdatePacket.class, 0x47
|
||||
SetExperiencePacket.class, 0x40,
|
||||
SpawnPositionPacket.class, 0x46
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
|
||||
/**
|
||||
* Set Experience packet.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |------------------|----------|------------------------|
|
||||
* | Experience bar | Float | Значение от 0.0 до 1.0 |
|
||||
* | Level | VarInt | |
|
||||
* | Total Experience | VarInt | |
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Set_Experience">Set Experience</a>
|
||||
* @see <a href="https://minecraft.fandom.com/wiki/Experience#Leveling_up">Experience: Leveling up</a>
|
||||
*/
|
||||
@Data
|
||||
public class SetExperiencePacket implements ServerSidePacket {
|
||||
|
||||
private float experienceBar;
|
||||
private int level;
|
||||
private int totalExperience;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeFloat(this.experienceBar);
|
||||
netByteBuf.writeVarInt(this.level);
|
||||
netByteBuf.writeVarInt(this.totalExperience);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
|
||||
/**
|
||||
* Обновление времени суток.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |-------------|------|----------------------------------------|
|
||||
* | World Age | Long | Время жизни мира. В тиках (tick) |
|
||||
* | Time of day | Long | Суточное время в тиках (tick), 0-24000 |
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Каждую секунду происходит 20 тиков.
|
||||
* В игровых сутках 24000 тиков, т.е. игровые сутки в Minecraft длятся 20 минут.
|
||||
* В Vanilla сервере значение "Time of day" увеличивается на 20 единиц каждую секунду.
|
||||
* </p>
|
||||
*
|
||||
* <p>Временные промежутки:</p>
|
||||
* <ul>
|
||||
* <li>0 - восход солнца</li>
|
||||
* <li>6000 - полдень</li>
|
||||
* <li>12000 - закат</li>
|
||||
* <li>18000 - полночь</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Time_Update">Time Update</a>
|
||||
*/
|
||||
@Data
|
||||
public class TimeUpdatePacket implements ServerSidePacket {
|
||||
|
||||
private long worldAge;
|
||||
private long timeOfDay;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeLong(this.worldAge);
|
||||
netByteBuf.writeLong(this.timeOfDay);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ package mc.server;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.protocol.*;
|
||||
import mc.protocol.ProtocolConstant;
|
||||
import mc.protocol.State;
|
||||
import mc.protocol.api.ConnectionContext;
|
||||
import mc.protocol.model.Location;
|
||||
import mc.protocol.model.Look;
|
||||
@@ -127,21 +128,23 @@ public class PacketHandler {
|
||||
|
||||
// -- Эксперименты -- //
|
||||
|
||||
var timeUpdatePacket = new TimeUpdatePacket();
|
||||
timeUpdatePacket.setWorldAge(0);
|
||||
timeUpdatePacket.setTimeOfDay(0);
|
||||
var setExperiencePacket = new SetExperiencePacket();
|
||||
setExperiencePacket.setExperienceBar(0f);
|
||||
setExperiencePacket.setLevel(0);
|
||||
setExperiencePacket.setTotalExperience(100);
|
||||
|
||||
while (true) {
|
||||
context.sendNow(timeUpdatePacket);
|
||||
context.sendNow(setExperiencePacket);
|
||||
|
||||
timeUpdatePacket.setTimeOfDay(timeUpdatePacket.getTimeOfDay() + 20);
|
||||
if (timeUpdatePacket.getTimeOfDay() >= 24_000) {
|
||||
timeUpdatePacket.setWorldAge(timeUpdatePacket.getWorldAge() + 1);
|
||||
timeUpdatePacket.setTimeOfDay(0);
|
||||
setExperiencePacket.setExperienceBar(setExperiencePacket.getExperienceBar() + 0.01f);
|
||||
setExperiencePacket.setLevel(setExperiencePacket.getLevel() + 1);
|
||||
if (setExperiencePacket.getExperienceBar() > 1.0f) {
|
||||
setExperiencePacket.setExperienceBar(0f);
|
||||
setExperiencePacket.setLevel(0);
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(5);
|
||||
TimeUnit.MILLISECONDS.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user