mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-14 10:35:20 +01:00
added Base for custom classic protocol extensions
This commit is contained in:
parent
e344d1165a
commit
59189686f3
@ -57,6 +57,7 @@ dependencies {
|
||||
libs "net.raphimc:ViaAprilFools:${project.viaaprilfools_version}"
|
||||
|
||||
libs "net.lenni0451.mcstructs:text:${project.mcstructs_text_version}"
|
||||
libs "net.lenni0451:Reflect:${project.reflect_version}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
@ -26,6 +26,7 @@ viaaprilfools_version=2.0.6
|
||||
|
||||
# lenni0451 libs
|
||||
mcstructs_text_version=2.2.0
|
||||
reflect_version=1.1.0
|
||||
|
||||
# other mods
|
||||
mod_menu_version=5.0.0
|
||||
|
@ -25,6 +25,7 @@ import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
|
||||
import de.florianmichael.viafabricplus.definition.ItemReleaseVersionDefinition;
|
||||
import de.florianmichael.viafabricplus.definition.PackFormatsDefinition;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.ClassicItemSelectionScreen;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions;
|
||||
import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider;
|
||||
import de.florianmichael.viafabricplus.definition.v1_8_x.ArmorPointsDefinition;
|
||||
import de.florianmichael.viafabricplus.platform.ViaAprilFoolsPlatformImpl;
|
||||
@ -80,6 +81,8 @@ public class ViaFabricPlus {
|
||||
});
|
||||
|
||||
public void preLoad() {
|
||||
CustomClassicProtocolExtensions.forceLoad();
|
||||
|
||||
ViaLoadingBase.ViaLoadingBaseBuilder builder = ViaLoadingBase.ViaLoadingBaseBuilder.create();
|
||||
|
||||
builder = builder.subPlatform(SUB_PLATFORM_VIA_LEGACY);
|
||||
@ -132,6 +135,7 @@ public class ViaFabricPlus {
|
||||
PackFormatsDefinition.load();
|
||||
ItemReleaseVersionDefinition.load();
|
||||
ArmorPointsDefinition.load();
|
||||
PackFormatsDefinition.checkOutdated(SharedConstants.getProtocolVersion());
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
try {
|
||||
|
@ -71,14 +71,14 @@ public class PackFormatsDefinition {
|
||||
}
|
||||
|
||||
public static void checkOutdated(final int nativeVersion) {
|
||||
if (!protocolMap.containsKey(nativeVersion))
|
||||
if (!protocolMap.containsKey(nativeVersion)) {
|
||||
throw new RuntimeException("The current version has no pack format registered");
|
||||
}
|
||||
|
||||
final GameVersion gameVersion = protocolMap.get(nativeVersion);
|
||||
if (!gameVersion.getName().equals(SharedConstants.getGameVersion().getName()) ||
|
||||
!gameVersion.getId().equals(SharedConstants.getGameVersion().getId()) ||
|
||||
gameVersion.getPackVersion(PackType.RESOURCE) != SharedConstants.getGameVersion().getPackVersion(PackType.RESOURCE))
|
||||
if (!gameVersion.getName().equals(SharedConstants.getGameVersion().getName()) || !gameVersion.getId().equals(SharedConstants.getGameVersion().getId()) || gameVersion.getPackVersion(PackType.RESOURCE) != SharedConstants.getGameVersion().getPackVersion(PackType.RESOURCE)) {
|
||||
throw new RuntimeException("The current version has no pack format registered");
|
||||
}
|
||||
}
|
||||
|
||||
public static GameVersion current() {
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) 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 de.florianmichael.viafabricplus.definition.c0_30;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.lenni0451.reflect.Enums;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.ClientboundPacketsc0_30cpe;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class CustomClassicProtocolExtensions {
|
||||
public final static List<ClassicProtocolExtension> ALLOWED_EXTENSIONS = Arrays.asList(ClassicProtocolExtension.ENV_WEATHER_TYPE);
|
||||
|
||||
public final static Map<Integer, ClientboundPacketsc0_30cpe> CUSTOM_PACKETS = new HashMap<>();
|
||||
public static ClientboundPacketsc0_30cpe EXT_WEATHER_TYPE;
|
||||
|
||||
public static void forceLoad() {
|
||||
EXT_WEATHER_TYPE = createNewPacket(ClassicProtocolExtension.ENV_WEATHER_TYPE, 31, (user, buf) -> buf.readByte());
|
||||
}
|
||||
|
||||
public static ClientboundPacketsc0_30cpe createNewPacket(final ClassicProtocolExtension classicProtocolExtension, final int packetId, final BiConsumer<UserConnection, ByteBuf> packetSplitter) {
|
||||
final ClientboundPacketsc0_30cpe packet = Enums.newInstance(ClientboundPacketsc0_30cpe.class, classicProtocolExtension.getName(), ClassicProtocolExtension.values().length, new Class[] { int.class, BiConsumer.class }, new Object[]{ packetId, packetSplitter });
|
||||
Enums.addEnumInstance(ClientboundPacketsc0_30cpe.class, packet);
|
||||
CUSTOM_PACKETS.put(packetId, packet);
|
||||
return packet;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) 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 de.florianmichael.viafabricplus.definition.c0_30.model;
|
||||
|
||||
public class WeatherTypes {
|
||||
|
||||
public final static byte SUNNY = 0;
|
||||
public final static byte RAINING = 1;
|
||||
public final static byte SNOWING = 2;
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) 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 de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy;
|
||||
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(value = ClassicProtocolExtension.class, remap = false)
|
||||
public class MixinClassicProtocolExtension {
|
||||
|
||||
@Inject(method = "supportsVersion", at = @At("HEAD"), cancellable = true)
|
||||
public void allowExtensions_supportsVersion(int version, CallbackInfoReturnable<Boolean> cir) {
|
||||
final ClassicProtocolExtension self = (ClassicProtocolExtension) (Object) this;
|
||||
if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains(self)) {
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "isSupported", at = @At("HEAD"), cancellable = true)
|
||||
public void allowExtensions_isSupported(CallbackInfoReturnable<Boolean> cir) {
|
||||
final ClassicProtocolExtension self = (ClassicProtocolExtension) (Object) this;
|
||||
if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains(self)) {
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getHighestSupportedVersion", at = @At("HEAD"), cancellable = true)
|
||||
public void allowExtensions_getHighestSupportedVersion(CallbackInfoReturnable<Integer> cir) {
|
||||
final ClassicProtocolExtension self = (ClassicProtocolExtension) (Object) this;
|
||||
if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains(self)) {
|
||||
cir.setReturnValue(1);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) 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 de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy;
|
||||
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.ClientboundPacketsc0_30cpe;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(value = ClientboundPacketsc0_30cpe.class, remap = false)
|
||||
public class MixinClientboundPacketsc0_30cpe {
|
||||
|
||||
@Inject(method = "getPacket", at = @At("HEAD"), cancellable = true)
|
||||
private static void addCustomPackets(int id, CallbackInfoReturnable<ClientboundPacketsc0_30cpe> cir) {
|
||||
if (CustomClassicProtocolExtensions.CUSTOM_PACKETS.containsKey(id)) {
|
||||
cir.setReturnValue(CustomClassicProtocolExtensions.CUSTOM_PACKETS.get(id));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) 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 de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.model.WeatherTypes;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.ClientboundPacketsc0_28;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.ServerboundPacketsc0_28;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.ClientboundPacketsc0_30cpe;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.Protocolc0_30toc0_30cpe;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.ServerboundPacketsc0_30cpe;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = Protocolc0_30toc0_30cpe.class, remap = false)
|
||||
public class MixinProtocolc0_30toc0_30cpe extends AbstractProtocol<ClientboundPacketsc0_30cpe, ClientboundPacketsc0_28, ServerboundPacketsc0_30cpe, ServerboundPacketsc0_28> {
|
||||
|
||||
@Inject(method = "registerPackets", at = @At("RETURN"))
|
||||
public void extendPackets(CallbackInfo ci) {
|
||||
this.registerClientbound(CustomClassicProtocolExtensions.EXT_WEATHER_TYPE, null, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
wrapper.cancel();
|
||||
final byte weatherType = wrapper.read(Type.BYTE);
|
||||
|
||||
final PacketWrapper changeRainState = PacketWrapper.create(ClientboundPackets1_19_3.GAME_EVENT, wrapper.user());
|
||||
changeRainState.write(Type.BYTE, weatherType == WeatherTypes.SUNNY ? (byte) 2 : (byte) 1); // start raining
|
||||
changeRainState.write(Type.FLOAT, 0F); // unused
|
||||
changeRainState.sendRaw();
|
||||
|
||||
final PacketWrapper changeRainType = PacketWrapper.create(ClientboundPackets1_19_3.GAME_EVENT, wrapper.user());
|
||||
changeRainType.write(Type.BYTE, (byte) 7);
|
||||
changeRainType.write(Type.FLOAT, weatherType == WeatherTypes.RAINING ? 0F : 1F);
|
||||
changeRainType.sendRaw();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -97,8 +97,11 @@
|
||||
"fixes.screen.screenhandler.MixinScreenHandler",
|
||||
"fixes.sodium.MixinChunkTracker",
|
||||
"fixes.viaaprilfools.MixinProtocol1_16to20w14infinite",
|
||||
"fixes.vialegacy.MixinClassicProtocolExtension",
|
||||
"fixes.vialegacy.MixinClientboundPacketsc0_30cpe",
|
||||
"fixes.vialegacy.MixinExtensionProtocolMetadataStorage",
|
||||
"fixes.vialegacy.MixinProtocol1_8to1_7_6_10",
|
||||
"fixes.vialegacy.MixinProtocolc0_30toc0_30cpe",
|
||||
"fixes.vialoadingbase.MixinVLBViaConfig",
|
||||
"fixes.viaversion.MixinCommonBoss",
|
||||
"fixes.viaversion.MixinProtocolVersion",
|
||||
|
Loading…
Reference in New Issue
Block a user