mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-26 17:37:41 +01:00
Fix 1.14->1.13 difficulty (#427)
This commit is contained in:
parent
2c341ab7ad
commit
5593dfb8e5
@ -26,6 +26,7 @@ import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets.EntityP
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets.PlayerPackets1_14;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets.SoundPackets1_14;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.DifficultyStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
@ -195,6 +196,8 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
|
||||
if (!user.has(ChunkLightStorage.class)) {
|
||||
user.put(new ChunkLightStorage(user));
|
||||
}
|
||||
|
||||
user.put(new DifficultyStorage(user));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.DifficultyStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
@ -309,21 +310,19 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
|
||||
handler(getTrackerHandler(Entity1_14Types.PLAYER, Type.INT));
|
||||
handler(getDimensionHandler(1));
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
|
||||
handler(wrapper -> {
|
||||
short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
|
||||
wrapper.write(Type.UNSIGNED_BYTE, difficulty);
|
||||
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Max Players
|
||||
wrapper.passthrough(Type.STRING); // Level Type
|
||||
wrapper.read(Type.VAR_INT); // Read View Distance
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Max Players
|
||||
wrapper.passthrough(Type.STRING); // Level Type
|
||||
wrapper.read(Type.VAR_INT); // Read View Distance
|
||||
|
||||
//TODO Track client position
|
||||
// Manually add position storage
|
||||
/*int entitiyId = wrapper.get(Type.INT, 0);
|
||||
StoredEntityData storedEntity = protocol.getEntityRewriter().tracker(wrapper.user()).entityData(entitiyId);
|
||||
storedEntity.put(new EntityPositionStorage1_14());*/
|
||||
}
|
||||
//TODO Track client position
|
||||
// Manually add position storage
|
||||
/*int entitiyId = wrapper.get(Type.INT, 0);
|
||||
StoredEntityData storedEntity = protocol.getEntityRewriter().tracker(wrapper.user()).entityData(entitiyId);
|
||||
storedEntity.put(new EntityPositionStorage1_14());*/
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -333,16 +332,15 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 0);
|
||||
clientWorld.setEnvironment(dimensionId);
|
||||
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 0); // Difficulty
|
||||
wrapper.user().get(ChunkLightStorage.class).clear();
|
||||
}
|
||||
short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
|
||||
wrapper.write(Type.UNSIGNED_BYTE, difficulty);
|
||||
|
||||
wrapper.user().get(ChunkLightStorage.class).clear();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets;
|
||||
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.DifficultyStorage;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
@ -40,6 +41,10 @@ public class PlayerPackets1_14 extends RewriterBase<Protocol1_13_2To1_14> {
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
map(Type.BOOLEAN, Type.NOTHING); // Locked
|
||||
handler(wrapper -> {
|
||||
byte difficulty = wrapper.get(Type.UNSIGNED_BYTE, 0).byteValue();
|
||||
wrapper.user().get(DifficultyStorage.class).setDifficulty(difficulty);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
public class DifficultyStorage extends StoredObject {
|
||||
private byte difficulty;
|
||||
|
||||
public DifficultyStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public byte getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public void setDifficulty(byte difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user