forked from SteamWar/SteamWar
Enhance compatibility and feature support for Minecraft 1.21: Add ProtocolWrapper21, update gamerule management, streamline entity tracking, and refine chunk hider logic.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import de.steamwar.Reflection;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
public class ProtocolWrapper21 implements ProtocolWrapper {
|
||||
|
||||
private static final Reflection.Field<List> equipmentStack = Reflection.getField(equipmentPacket, List.class, 0);
|
||||
@Override
|
||||
public void setEquipmentPacketStack(Object packet, Object slot, Object stack) {
|
||||
equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack)));
|
||||
}
|
||||
|
||||
private static final Reflection.Constructor removePacketConstructor = Reflection.getConstructor(ClientboundPlayerInfoRemovePacket.class, List.class);
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode) {
|
||||
if(action == PlayerInfoAction.REMOVE)
|
||||
return removePacketConstructor.invoke(Collections.singletonList(profile.getId()));
|
||||
return switch (action) {
|
||||
case ADD -> new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE), new ClientboundPlayerInfoUpdatePacket.Entry(
|
||||
profile.getId(), profile, true, 0, GameType.byId(mode.getValue()), null, true, 0, null
|
||||
));
|
||||
case GAMEMODE -> new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE), new ClientboundPlayerInfoUpdatePacket.Entry(
|
||||
profile.getId(), profile, true, 0, GameType.byId(mode.getValue()), null, true, 0, null
|
||||
));
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initTPSWarp(LongSupplier longSupplier) {
|
||||
Util.timeSource = () -> System.nanoTime() + longSupplier.getAsLong();
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,9 @@ public class ChunkHider21 implements ChunkHider {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int pos = (((y * 16) + z) * 16) + x;
|
||||
|
||||
switch (section.test(x, y, z)) {
|
||||
TechHider.State test = section.test(x, y, z);
|
||||
|
||||
switch (test) {
|
||||
case SKIP:
|
||||
break;
|
||||
case CHECK:
|
||||
|
||||
@@ -157,14 +157,21 @@ public final class Reflection {
|
||||
} else if(MAJOR_VERSION < 21 || MINOR_VERSION < 4) {
|
||||
return Class.forName(spigotClassnames.getOrDefault(name, name));
|
||||
} else {
|
||||
Class<?> clazz = Class.forName(name);
|
||||
if (clazz.getName().equals(name)) {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = Class.forName(name);
|
||||
} catch (ClassNotFoundException e) {}
|
||||
if (clazz != null && clazz.getName().equals(name)) {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
try {
|
||||
return Core.class.getClassLoader().getParent().loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (clazz == null) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,8 +147,9 @@ public interface ChunkHider {
|
||||
return;
|
||||
}
|
||||
|
||||
int longs = (int) (((long) entries * bitsPerBlock + 63) >> 6);
|
||||
out.writeBytes(in, longs * Long.BYTES);
|
||||
char valuesPerLong = (char)(64 / bitsPerBlock);
|
||||
int i1 = (entries + valuesPerLong - 1) / valuesPerLong;
|
||||
out.writeBytes(in, i1 * Long.BYTES);
|
||||
}
|
||||
|
||||
public long[] readDataArray() {
|
||||
@@ -164,9 +165,10 @@ public interface ChunkHider {
|
||||
return new long[entries];
|
||||
}
|
||||
|
||||
int longs = (int) (((long) entries * bitsPerBlock + 63) >> 6);
|
||||
long[] array = new long[longs];
|
||||
for(int i = 0; i < longs; i++)
|
||||
char valuesPerLong = (char) (64 / bitsPerBlock);
|
||||
int i1 = (entries + valuesPerLong - 1) / valuesPerLong;
|
||||
long[] array = new long[i1];
|
||||
for(int i = 0; i < i1; i++)
|
||||
array[i] = in.readLong();
|
||||
|
||||
return array;
|
||||
|
||||
Reference in New Issue
Block a user