Compare commits
1 Commits
dev/timeup
...
dev/experi
| Author | SHA1 | Date | |
|---|---|---|---|
|
346d64aea5
|
@@ -60,8 +60,8 @@ public enum State {
|
|||||||
JoinGamePacket.class, 0x23,
|
JoinGamePacket.class, 0x23,
|
||||||
PlayerAbilitiesPacket.class,0x2C,
|
PlayerAbilitiesPacket.class,0x2C,
|
||||||
SPlayerPositionAndLookPacket.class, 0x2F,
|
SPlayerPositionAndLookPacket.class, 0x2F,
|
||||||
SpawnPositionPacket.class, 0x46,
|
SetExperiencePacket.class, 0x40,
|
||||||
TimeUpdatePacket.class, 0x47
|
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.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.protocol.*;
|
import mc.protocol.ProtocolConstant;
|
||||||
|
import mc.protocol.State;
|
||||||
import mc.protocol.api.ConnectionContext;
|
import mc.protocol.api.ConnectionContext;
|
||||||
import mc.protocol.model.Location;
|
import mc.protocol.model.Location;
|
||||||
import mc.protocol.model.Look;
|
import mc.protocol.model.Look;
|
||||||
@@ -127,21 +128,23 @@ public class PacketHandler {
|
|||||||
|
|
||||||
// -- Эксперименты -- //
|
// -- Эксперименты -- //
|
||||||
|
|
||||||
var timeUpdatePacket = new TimeUpdatePacket();
|
var setExperiencePacket = new SetExperiencePacket();
|
||||||
timeUpdatePacket.setWorldAge(0);
|
setExperiencePacket.setExperienceBar(0f);
|
||||||
timeUpdatePacket.setTimeOfDay(0);
|
setExperiencePacket.setLevel(0);
|
||||||
|
setExperiencePacket.setTotalExperience(100);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
context.sendNow(timeUpdatePacket);
|
context.sendNow(setExperiencePacket);
|
||||||
|
|
||||||
timeUpdatePacket.setTimeOfDay(timeUpdatePacket.getTimeOfDay() + 20);
|
setExperiencePacket.setExperienceBar(setExperiencePacket.getExperienceBar() + 0.01f);
|
||||||
if (timeUpdatePacket.getTimeOfDay() >= 24_000) {
|
setExperiencePacket.setLevel(setExperiencePacket.getLevel() + 1);
|
||||||
timeUpdatePacket.setWorldAge(timeUpdatePacket.getWorldAge() + 1);
|
if (setExperiencePacket.getExperienceBar() > 1.0f) {
|
||||||
timeUpdatePacket.setTimeOfDay(0);
|
setExperiencePacket.setExperienceBar(0f);
|
||||||
|
setExperiencePacket.setLevel(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TimeUnit.MILLISECONDS.sleep(5);
|
TimeUnit.MILLISECONDS.sleep(10);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user