Skip to content

Commit

Permalink
Add support for downloading multiple external resource packs with aut…
Browse files Browse the repository at this point in the history
…ohost
  • Loading branch information
Patbox committed Jan 11, 2024
1 parent a465537 commit 61d61bf
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.91.1+1.20.4

maven_group = eu.pb4

mod_version = 0.7.5
mod_version = 0.7.6-dev

minecraft_version_supported = ">=1.20.3-"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -38,6 +39,10 @@ default Collection<MinecraftServer.ServerResourcePackProperties> getProperties()
};

static MinecraftServer.ServerResourcePackProperties createProperties(@Nullable UUID uuid, String address, @Nullable String hash) {
return new MinecraftServer.ServerResourcePackProperties(uuid, address, hash, AutoHost.config.require || PolymerResourcePackUtils.isRequired(), AutoHost.message);
return new MinecraftServer.ServerResourcePackProperties(uuid != null
? uuid : UUID.nameUUIDFromBytes(address.getBytes(StandardCharsets.UTF_8)),
address,
hash != null ? hash : "",
AutoHost.config.require || PolymerResourcePackUtils.isRequired(), AutoHost.message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand All @@ -34,6 +36,9 @@ public class AutoHost implements ModInitializer {

public static ResourcePackDataProvider provider = EmptyProvider.INSTANCE;

public static final List<MinecraftServer.ServerResourcePackProperties> GLOBAL_RESOURCE_PACKS = new ArrayList<>();


public static void init(MinecraftServer server) {
var config = CommonImpl.loadConfig("auto-host", AutoHostConfig.class);
AutoHost.config = config;
Expand Down Expand Up @@ -71,6 +76,14 @@ public static void init(MinecraftServer server) {

config.providerSettings = provider.saveSettings();

GLOBAL_RESOURCE_PACKS.clear();
for (var x : config.externalResourcePacks) {
if (x.url != null) {
GLOBAL_RESOURCE_PACKS.add(ResourcePackDataProvider.createProperties(x.id, x.url, x.hash));
}
}


CommonImpl.saveConfig("auto-host", config);

provider.serverStarted(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import com.google.gson.annotations.SerializedName;
import eu.pb4.polymer.common.impl.CommonImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


public class AutoHostConfig {
public String _c1 = "Enables Polymer's ResourcePack Auto Hosting";
Expand All @@ -19,10 +23,18 @@ public class AutoHostConfig {
public String _c4 = "Configuration of type, see provider's source for more details";
@SerializedName("settings")
public JsonElement providerSettings = new JsonObject();

public String _c5 = "Message sent to clients before pack is loaded";
public JsonElement message = new JsonPrimitive("This server uses resource pack to enhance gameplay with custom textures and models. It might be unplayable without them.");
public String _c6 = "Disconnect message in case of failure";
@SerializedName("disconnect_message")
public JsonElement disconnectMessage = new JsonPrimitive("Couldn't apply server resourcepack!");

@SerializedName("external_resource_packs")
public List<ExternalResourcePack> externalResourcePacks = new ArrayList<>();

public static class ExternalResourcePack {
public UUID id;
public String url;
public String hash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.ArrayList;
import java.util.Queue;

@Mixin(ServerConfigurationNetworkHandler.class)
Expand All @@ -37,7 +38,11 @@ public ServerConfigurationNetworkHandlerMixin(MinecraftServer server, ClientConn
@Inject(method = "queueSendResourcePackTask", at = @At("TAIL"))
private void polymerAutoHost$addTask(CallbackInfo ci) {
if (AutoHost.config.enabled) {
this.tasks.add(new AutoHostTask(AutoHost.provider.getProperties(this.connection)));
var x = new ArrayList<MinecraftServer.ServerResourcePackProperties>();
x.addAll(AutoHost.provider.getProperties(this.connection));
x.addAll(AutoHost.GLOBAL_RESOURCE_PACKS);

this.tasks.add(new AutoHostTask(x));
}
}

Expand Down

0 comments on commit 61d61bf

Please sign in to comment.