Complete adding forge 1.17.1

This commit is contained in:
Blue (Lukas Rieger) 2021-11-20 15:06:52 +01:00
parent ae00af5860
commit 23fcab94ac
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800
8 changed files with 88 additions and 78 deletions

View File

@ -30,6 +30,7 @@
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ForkJoinPool;
public class BlueMap {

View File

@ -38,7 +38,7 @@ public class MinecraftVersion implements Comparable<MinecraftVersion> {
private static final Pattern VERSION_REGEX = Pattern.compile("(?:(?<major>\\d+)\\.(?<minor>\\d+))(?:\\.(?<patch>\\d+))?(?:\\-(?:pre|rc)\\d+)?");
public static final MinecraftVersion LATEST_SUPPORTED = new MinecraftVersion(1, 17, 0);
public static final MinecraftVersion LATEST_SUPPORTED = new MinecraftVersion(1, 18, 0);
public static final MinecraftVersion EARLIEST_SUPPORTED = new MinecraftVersion(1, 13);
private final int major, minor, patch;

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -10,6 +10,8 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle'
targetCompatibility = 1.16
minecraft {
mappings channel: 'official', version: '1.17.1'
}
@ -33,7 +35,7 @@ dependencies {
build.dependsOn shadowJar {
destinationDirectory = file '../../build/release'
archiveFileName.set("BlueMap-${archiveVersion.get()}-forge-1.16.4.jar")
archiveFileName.set("BlueMap-${archiveVersion.get()}-forge-1.17.1.jar")
configurations = [project.configurations.include]

View File

@ -24,25 +24,27 @@
*/
package de.bluecolored.bluemap.forge;
import java.io.IOException;
import java.util.Optional;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
import de.bluecolored.bluemap.common.plugin.text.Text;
import de.bluecolored.bluemap.core.world.World;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.phys.Vec3;
import java.io.IOException;
import java.util.Optional;
public class ForgeCommandSource implements CommandSource {
private ForgeMod mod;
private Plugin plugin;
private net.minecraft.command.CommandSource delegate;
private CommandSourceStack delegate;
public ForgeCommandSource(ForgeMod mod, Plugin plugin, net.minecraft.command.CommandSource delegate) {
public ForgeCommandSource(ForgeMod mod, Plugin plugin, CommandSourceStack delegate) {
this.mod = mod;
this.plugin = plugin;
this.delegate = delegate;
@ -50,31 +52,27 @@ public ForgeCommandSource(ForgeMod mod, Plugin plugin, net.minecraft.command.Com
@Override
public void sendMessage(Text text) {
delegate.sendFeedback(ITextComponent.Serializer.func_240643_a_(text.toJSONString()), false);
Component component = TextComponent.Serializer.fromJsonLenient(text.toJSONString());
if (component == null) component = new TextComponent(text.toPlainString());
delegate.sendSuccess(component, false);
}
@Override
public boolean hasPermission(String permission) {
return delegate.hasPermissionLevel(1);
return delegate.hasPermission(1);
}
@Override
public Optional<Vector3d> getPosition() {
net.minecraft.util.math.vector.Vector3d pos = delegate.getPos();
if (pos != null) {
return Optional.of(new Vector3d(pos.x, pos.y, pos.z));
}
return Optional.empty();
Vec3 pos = delegate.getPosition();
return Optional.of(new Vector3d(pos.x, pos.y, pos.z));
}
@Override
public Optional<World> getWorld() {
try {
ServerWorld world = delegate.getWorld();
if (world != null) {
return Optional.ofNullable(plugin.getWorld(mod.getUUIDForWorld(world)));
}
ServerLevel world = delegate.getLevel();
return Optional.ofNullable(plugin.getWorld(mod.getUUIDForWorld(world)));
} catch (IOException ignore) {}
return Optional.empty();

View File

@ -54,13 +54,13 @@ public synchronized void removeAllListeners() {
@SubscribeEvent
public synchronized void onPlayerJoin(PlayerLoggedInEvent evt) {
UUID uuid = evt.getPlayer().getUniqueID();
UUID uuid = evt.getPlayer().getUUID();
for (ServerEventListener listener : eventListeners) listener.onPlayerJoin(uuid);
}
@SubscribeEvent
public synchronized void onPlayerLeave(PlayerLoggedOutEvent evt) {
UUID uuid = evt.getPlayer().getUniqueID();
UUID uuid = evt.getPlayer().getUUID();
for (ServerEventListener listener : eventListeners) listener.onPlayerLeave(uuid);
}

View File

@ -35,25 +35,24 @@
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.DimensionType;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.FolderName;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.storage.LevelResource;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
import net.minecraftforge.fml.network.FMLNetworkConstants;
import org.apache.commons.lang3.tuple.Pair;
import net.minecraftforge.fmllegacy.network.FMLNetworkConstants;
import net.minecraftforge.fmlserverevents.FMLServerStartedEvent;
import net.minecraftforge.fmlserverevents.FMLServerStartingEvent;
import net.minecraftforge.fmlserverevents.FMLServerStoppingEvent;
import org.apache.logging.log4j.LogManager;
import java.io.File;
@ -66,17 +65,17 @@
@Mod(Plugin.PLUGIN_ID)
public class ForgeMod implements ServerInterface {
private Plugin pluginInstance = null;
private final Plugin pluginInstance;
private MinecraftServer serverInstance = null;
private Map<File, UUID> worldUUIDs;
private ForgeEventForwarder eventForwarder;
private final Map<File, UUID> worldUUIDs;
private final ForgeEventForwarder eventForwarder;
private LoadingCache<ServerWorld, UUID> worldUuidCache;
private final LoadingCache<ServerLevel, UUID> worldUuidCache;
private int playerUpdateIndex = 0;
private Map<UUID, Player> onlinePlayerMap;
private List<ForgePlayer> onlinePlayerList;
private final Map<UUID, Player> onlinePlayerMap;
private final List<ForgePlayer> onlinePlayerList;
public ForgeMod() {
Logger.global = new Log4jLogger(LogManager.getLogger(Plugin.PLUGIN_NAME));
@ -84,7 +83,16 @@ public ForgeMod() {
this.onlinePlayerMap = new ConcurrentHashMap<>();
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
this.pluginInstance = new Plugin(new MinecraftVersion(1, 16, 2), "forge-1.16.2", this);
String versionString = net.minecraft.DetectedVersion.tryDetectVersion().getId();
MinecraftVersion mcVersion;
try {
mcVersion = MinecraftVersion.of(versionString);
} catch (IllegalArgumentException ex) {
mcVersion = new MinecraftVersion(1, 17, 1);
Logger.global.logWarning("Failed to derive version from version-string '" + versionString +
"', falling back to version: " + mcVersion.getVersionString());
}
this.pluginInstance = new Plugin(mcVersion, "forge-1.16.2", this);
this.worldUUIDs = new ConcurrentHashMap<>();
this.eventForwarder = new ForgeEventForwarder();
@ -97,7 +105,7 @@ public ForgeMod() {
MinecraftForge.EVENT_BUS.register(this);
//Make sure the mod being absent on the other network side does not cause the client to display the server as incompatible
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true));
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true));
}
@SubscribeEvent
@ -105,13 +113,13 @@ public void onServerStarting(FMLServerStartingEvent event) {
this.serverInstance = event.getServer();
//register commands
new Commands<>(pluginInstance, event.getServer().getCommandManager().getDispatcher(), forgeSource -> new ForgeCommandSource(this, pluginInstance, forgeSource));
new Commands<>(pluginInstance, event.getServer().getCommands().getDispatcher(), forgeSource -> new ForgeCommandSource(this, pluginInstance, forgeSource));
}
@SubscribeEvent
public void onServerStarted(FMLServerStartedEvent event) {
//save worlds to generate level.dat files
serverInstance.save(false, true, true);
serverInstance.saveAllChunks(false, true, true);
new Thread(() -> {
Logger.global.logInfo("Loading...");
@ -160,7 +168,7 @@ public UUID getUUIDForWorld(File worldFolder) throws IOException {
return uuid;
}
public UUID getUUIDForWorld(ServerWorld world) throws IOException {
public UUID getUUIDForWorld(ServerLevel world) throws IOException {
try {
return worldUuidCache.get(world);
} catch (RuntimeException e) {
@ -168,7 +176,7 @@ public UUID getUUIDForWorld(ServerWorld world) throws IOException {
}
}
private UUID loadUUIDForWorld(ServerWorld world) throws IOException {
private UUID loadUUIDForWorld(ServerLevel world) throws IOException {
File key = getFolderForWorld(world);
UUID uuid = worldUUIDs.get(key);
@ -180,10 +188,10 @@ private UUID loadUUIDForWorld(ServerWorld world) throws IOException {
return uuid;
}
private File getFolderForWorld(ServerWorld world) throws IOException {
private File getFolderForWorld(ServerLevel world) throws IOException {
MinecraftServer server = world.getServer();
File worldFolder = world.getServer().getDataDirectory().toPath().resolve(server.func_240776_a_(FolderName.field_237253_i_)).toFile();
File dimensionFolder = DimensionType.func_236031_a_(world.func_234923_W_(), worldFolder);
File worldFolder = world.getServer().getServerDirectory().toPath().resolve(server.getWorldPath(LevelResource.ROOT)).toFile();
File dimensionFolder = DimensionType.getStorageFolder(world.dimension(), worldFolder);
return dimensionFolder.getCanonicalFile();
}
@ -193,7 +201,7 @@ public boolean persistWorldChanges(UUID worldUUID) throws IOException, IllegalAr
serverInstance.execute(() -> {
try {
for (ServerWorld world : serverInstance.getWorlds()) {
for (ServerLevel world : serverInstance.getAllLevels()) {
if (getUUIDForWorld(world).equals(worldUUID)) {
world.save(null, true, false);
}
@ -225,20 +233,20 @@ public File getConfigFolder() {
@SubscribeEvent
public void onPlayerJoin(PlayerLoggedInEvent evt) {
PlayerEntity playerInstance = evt.getPlayer();
if (!(playerInstance instanceof ServerPlayerEntity)) return;
net.minecraft.world.entity.player.Player playerInstance = evt.getPlayer();
if (!(playerInstance instanceof ServerPlayer)) return;
ForgePlayer player = new ForgePlayer(this, playerInstance.getUniqueID());
ForgePlayer player = new ForgePlayer(this, playerInstance.getUUID());
onlinePlayerMap.put(player.getUuid(), player);
onlinePlayerList.add(player);
}
@SubscribeEvent
public void onPlayerLeave(PlayerLoggedOutEvent evt) {
PlayerEntity player = evt.getPlayer();
if (!(player instanceof ServerPlayerEntity)) return;
net.minecraft.world.entity.player.Player player = evt.getPlayer();
if (!(player instanceof ServerPlayer)) return;
UUID playerUUID = player.getUniqueID();
UUID playerUUID = player.getUUID();
onlinePlayerMap.remove(playerUUID);
synchronized (onlinePlayerList) {
onlinePlayerList.removeIf(p -> p.getUuid().equals(playerUUID));

View File

@ -24,22 +24,24 @@
*/
package de.bluecolored.bluemap.forge;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.serverinterface.Gamemode;
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
import de.bluecolored.bluemap.common.plugin.text.Text;
import net.minecraft.client.renderer.EffectInstance;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.level.GameType;
import net.minecraft.world.phys.Vec3;
import java.io.IOException;
import java.util.EnumMap;
import java.util.Map;
import java.util.UUID;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.common.plugin.serverinterface.Gamemode;
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
import de.bluecolored.bluemap.common.plugin.text.Text;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.GameType;
public class ForgePlayer implements Player {
private static final UUID UNKNOWN_WORLD_UUID = UUID.randomUUID();
@ -50,7 +52,6 @@ public class ForgePlayer implements Player {
GAMEMODE_MAP.put(GameType.SURVIVAL, Gamemode.SURVIVAL);
GAMEMODE_MAP.put(GameType.CREATIVE, Gamemode.CREATIVE);
GAMEMODE_MAP.put(GameType.SPECTATOR, Gamemode.SPECTATOR);
GAMEMODE_MAP.put(GameType.NOT_SET, Gamemode.SURVIVAL);
}
private UUID uuid;
@ -121,28 +122,28 @@ public void update() {
return;
}
ServerPlayerEntity player = server.getPlayerList().getPlayerByUUID(uuid);
ServerPlayer player = server.getPlayerList().getPlayer(uuid);
if (player == null) {
this.online = false;
return;
}
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType());
this.gamemode = GAMEMODE_MAP.getOrDefault(player.gameMode.getGameModeForPlayer(), Gamemode.SURVIVAL);
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY);
MobEffectInstance invis = player.getEffect(MobEffects.INVISIBILITY);
this.invisible = invis != null && invis.getDuration() > 0;
this.name = Text.of(player.getName().getString());
this.online = true;
net.minecraft.util.math.vector.Vector3d pos = player.getPositionVec();
this.position = new Vector3d(pos.getX(), pos.getY(), pos.getZ());
this.sneaking = player.isSneaking();
Vec3 pos = player.getPosition(1f);
this.position = new Vector3d(pos.x(), pos.y(), pos.z());
this.sneaking = player.isCrouching();
try {
this.world = mod.getUUIDForWorld(player.getServerWorld());
} catch (IOException e) {
this.world = mod.getUUIDForWorld((ServerLevel) player.getCommandSenderWorld());
} catch (IOException | ClassCastException e) {
this.world = UNKNOWN_WORLD_UUID;
}
}