Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
environment = client
min_mc_version = 1.8.2-pre5
max_mc_version = 1.12.2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.ornithemc.osl.resource.loader.api.server;

import net.minecraft.world.gen.loot.LootTables;

public interface MinecraftServerExtension {

LootTables getLootTables();

void reloadResources();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.ornithemc.osl.resource.loader.api.server.resource.reload;

import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
import net.ornithemc.osl.resource.loader.api.resource.ResourceType;
import net.ornithemc.osl.resource.loader.impl.resource.reload.ResourceReloaders;

public final class DataReloaders {

public static final NamespacedIdentifier CRAFTING_MANAGER = vanilla("recipes");
public static final NamespacedIdentifier LOOT_TABLE_MANAGER = vanilla("loot_tables");
public static final NamespacedIdentifier FUNCTION_MANAGER = vanilla("functions");
public static final NamespacedIdentifier ADVANCEMENT_MANAGER = vanilla("advancements");
public static final NamespacedIdentifier STRUCTURE_MANAGER = vanilla("structures");

public static final NamespacedIdentifier BEFORE_VANILLA = ResourceReloaders.BEFORE_VANILLA;
public static final NamespacedIdentifier AFTER_VANILLA = ResourceReloaders.AFTER_VANILLA;

private static NamespacedIdentifier vanilla(String identifier) {
return ResourceReloaders.vanilla(ResourceType.SERVER_DATA, identifier);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.ornithemc.osl.resource.loader.api.world;

import java.util.Set;

public interface WorldDataExtension {

Set<String> getDisabledDataPacks();

Set<String> getEnabledDataPacks();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package net.ornithemc.osl.resource.loader.impl;

import java.io.InputStream;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import net.fabricmc.loader.api.FabricLoader;

import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
import net.ornithemc.osl.core.api.util.function.IOSupplier;
import net.ornithemc.osl.core.impl.util.MinecraftVersion;
import net.ornithemc.osl.resource.loader.api.resource.ResourceType;
import net.ornithemc.osl.resource.loader.api.resource.pack.ResourceConsumer;
import net.ornithemc.osl.resource.loader.impl.resource.pack.ModContainerResourcePack;
import net.ornithemc.osl.resource.loader.impl.resource.pack.ResourcePacks;
import net.ornithemc.osl.text.api.TextComponents;

public class DefaultDataPack extends ModContainerResourcePack {

private static final boolean LOOT_TABLES_EXIST = MinecraftVersion.resolve().compareTo("15w43a") >= 0;
private static final boolean FUNCTIONS_EXIST = MinecraftVersion.resolve().compareTo("1.12-pre1") >= 0;
private static final boolean ADVANCEMENTS_EXIST = MinecraftVersion.resolve().compareTo("17w13a") >= 0;

private final Set<String> directoriesToRedirect = new HashSet<>();
private final boolean shouldRedirectSomeDirectories;

public DefaultDataPack() {
super(FabricLoader.getInstance().getModContainer("minecraft").get(), ".", "Default");

// this.directoriesToRedirect.add("recipes"); // TODO: support re-loading crafting recipes
if (LOOT_TABLES_EXIST) {
this.directoriesToRedirect.add("loot_tables");
}
if (FUNCTIONS_EXIST) {
this.directoriesToRedirect.add("advancements");
}
if (ADVANCEMENTS_EXIST) {
this.directoriesToRedirect.add("structures");
}

this.shouldRedirectSomeDirectories = !this.directoriesToRedirect.isEmpty();
}

@Override
protected IOSupplier<InputStream> generateMetadataFile() {
return ResourcePacks.generateMetadataFile(TextComponents.literal("The default behavior of Minecraft"));
}

@Override
protected IOSupplier<InputStream> generateIconFile() {
return ModContainerResourcePack.getIcon(this.mod);
}

@Override
protected Map<ResourceType, Set<String>> findNamespaces() {
return Collections.singletonMap(ResourceType.SERVER_DATA, Collections.singleton("minecraft"));
}

private boolean shouldRedirectToAssets(String path) {
return this.directoriesToRedirect.stream().anyMatch(dir -> path.equals(dir) || path.startsWith(dir + "/"));
}

private ResourceType updateResourceType(ResourceType type, NamespacedIdentifier location) {
return this.updateResourceType(type, location.identifier());
}

private ResourceType updateResourceType(ResourceType type, String path) {
if (this.shouldRedirectSomeDirectories && this.shouldRedirectToAssets(path)) {
type = ResourceType.CLIENT_ASSETS;
}

return type;
}

@Override
public boolean hasResource(ResourceType type, NamespacedIdentifier location) {
return super.hasResource(this.updateResourceType(type, location), location);
}

@Override
public IOSupplier<InputStream> getResource(ResourceType type, NamespacedIdentifier location) {
return super.getResource(this.updateResourceType(type, location), location);
}

@Override
public void findResources(ResourceType type, String namespace, String directory, ResourceConsumer consumer) {
super.findResources(this.updateResourceType(type, directory), namespace, directory, consumer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.ornithemc.osl.resource.loader.impl;

import net.ornithemc.osl.resource.loader.api.resource.pack.ResourcePack;
import net.ornithemc.osl.resource.loader.impl.resource.repository.AbstractServerPackSource;

public class ServerResourcePacks extends AbstractServerPackSource {

private ResourcePack defaultPack;

public ServerResourcePacks() {
this.defaultPack = new DefaultDataPack();
}

@Override
protected ResourcePack getOrWrapDefaultPack() {
return this.defaultPack;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.ornithemc.osl.resource.loader.impl.access;

import com.google.gson.Gson;

import net.ornithemc.osl.resource.loader.api.resource.manager.ResourceManager;

public interface LootTablesAccess {

Gson osl$resource_loader$getGson();

ResourceManager osl$resource_loader$getResourceManager();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package net.ornithemc.osl.resource.loader.impl.mixin.client;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.llamalad7.mixinextras.sugar.Local;

import net.minecraft.server.AdvancementManager;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.world.WorldData;
import net.minecraft.world.gen.loot.LootTables;
import net.minecraft.world.storage.WorldStorage;

import net.ornithemc.conditionalmixin.annotations.Conditional;
import net.ornithemc.conditionalmixin.annotations.Version;

import net.ornithemc.osl.resource.loader.impl.mixin.common.MinecraftServerMixin;

@Mixin(IntegratedServer.class)
public class IntegratedServerMixin extends MinecraftServerMixin {

@Inject(
method = "loadWorld",
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/storage/WorldStorage;loadData()Lnet/minecraft/world/WorldData;"
)
),
at = @At(
// inject before the for-loop for ServerWorld instancing
value = "FIELD",
target = "Lnet/minecraft/server/integrated/IntegratedServer;worlds:[Lnet/minecraft/server/world/ServerWorld;",
ordinal = 0,
shift = Shift.BY,
// it's extreme but this ensures that the injector is only invoked once
by = -5
)
)
private void osl$resource_loader$loadDataPacks(CallbackInfo ci, @Local WorldStorage storage, @Local WorldData data) {
this.onLoadWorldBeforeCreateServerWorlds(storage, data);
}

@Conditional(minecraftVersion = @Version(">=15w43a <17w18a"))
@Redirect(
method = "m_90502033",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/gen/loot/LootTables;reload()V"
)
)
private void osl$resource_loader$cancelLootTablesReload(LootTables lootTables) {
// the loot table manager is added as a resource reload listener
}

@Conditional(minecraftVersion = @Version(">=17w15a <17w18a"))
@Redirect(
method = "m_90502033",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/AdvancementManager;reload()V"
)
)
private void osl$resource_loader$cancelAdvancementsReload(AdvancementManager advancements) {
// the advancement manager is added as a resource reload listener
}

@Conditional(minecraftVersion = @Version(">=15w43a <17w15a"))
@Inject(
method = "m_90502033",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/gen/loot/LootTables;reload()V",
shift = Shift.AFTER
)
)
private void osl$resource_loader$reloadResourcesPreAdvancements(CallbackInfo ci) {
this.reloadDataPacks(this.worlds[0].getData());
}

@Conditional(minecraftVersion = @Version(">=17w15a <17w18a"))
@Inject(
method = "m_90502033",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;reloadResources()V"
)
)
private void osl$resource_loader$reloadResourcesPostAdvancements(CallbackInfo ci) {
this.reloadDataPacks(this.worlds[0].getData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.client.sound.system.SoundManager;
import net.minecraft.client.world.color.FoliageColorReloader;
import net.minecraft.client.world.color.GrassColorReloader;
import net.minecraft.server.integrated.IntegratedServer;

import net.ornithemc.conditionalmixin.annotations.Conditional;
import net.ornithemc.conditionalmixin.annotations.Version;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class MinecraftMixin {
private BuiltInResourcePack defaultResourcePack;
@Shadow
private ReloadableResourceManager resourceManager;
@Shadow
private IntegratedServer server;

@Shadow
private LanguageManager languageManager;
Expand Down Expand Up @@ -158,6 +161,19 @@ public class MinecraftMixin {
this.actualResourceManager.partialReload();
}

@Conditional(minecraftVersion = @Version("<15w43a"))
@Inject(
method = "reloadResources",
at = @At(
value = "HEAD"
)
)
private void osl$resource_loader$reloadServerResources(CallbackInfo ci) {
if (this.server != null) {
this.server.reloadResources();
}
}

@Inject(
method = "reloadResources",
at = @At(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void load() { }
this.packRepository.setCallbacks(null, this::selectionChanged);

this.packRepository.addSource(new ClientResourcePacks((ResourcePacks) (Object) this));
this.packRepository.addSource(new BundledModResourcePacks());
this.packRepository.addSource(BundledModResourcePacks.client());
this.packRepository.addSource(this); // resourcepacks/ directory source

this.packRepository.init();
Expand Down
Loading
Loading