fix reloadable server resources

This commit is contained in:
yrsegal@gmail.com 2022-05-26 13:17:27 -04:00
parent 0858c7664f
commit 7eea96ec60

View file

@ -12,23 +12,26 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
@Mixin(ReloadableServerResources.class)
public class MixinReloadableServerResources {
@Inject(method = "lambda$loadResources$0", at = @At("RETURN"))
private static void onLoadResources(ReloadableServerResources rsr, Object whoKnows,
CallbackInfoReturnable<ReloadableServerResources> cir) {
var amethystTable = rsr.getLootTables().get(Blocks.AMETHYST_CLUSTER.getLootTable());
var theCoolerAmethystTable = (AccessorLootTable) amethystTable;
var oldFuncs = theCoolerAmethystTable.hex$getFunctions();
var newFuncs = Arrays.copyOf(oldFuncs, oldFuncs.length + 1);
var shardReducer = rsr.getItemModifierManager().get(HexLootHandler.FUNC_AMETHYST_SHARD_REDUCER);
if (shardReducer != null) {
newFuncs[newFuncs.length - 1] = shardReducer;
theCoolerAmethystTable.hex$setFunctions(newFuncs);
theCoolerAmethystTable.hex$setCompositeFunction(LootItemFunctions.compose(newFuncs));
} else {
HexAPI.LOGGER.warn("{} was not found?", HexLootHandler.FUNC_AMETHYST_SHARD_REDUCER);
}
@Inject(method = "loadResources", at = @At("RETURN"), cancellable = true)
private static void onLoadResources(CallbackInfoReturnable<CompletableFuture<ReloadableServerResources>> cir) {
cir.setReturnValue(cir.getReturnValue().thenApply((rsr) -> {
var amethystTable = rsr.getLootTables().get(Blocks.AMETHYST_CLUSTER.getLootTable());
var theCoolerAmethystTable = (AccessorLootTable) amethystTable;
var oldFuncs = theCoolerAmethystTable.hex$getFunctions();
var newFuncs = Arrays.copyOf(oldFuncs, oldFuncs.length + 1);
var shardReducer = rsr.getItemModifierManager().get(HexLootHandler.FUNC_AMETHYST_SHARD_REDUCER);
if (shardReducer != null) {
newFuncs[newFuncs.length - 1] = shardReducer;
theCoolerAmethystTable.hex$setFunctions(newFuncs);
theCoolerAmethystTable.hex$setCompositeFunction(LootItemFunctions.compose(newFuncs));
} else {
HexAPI.LOGGER.warn("{} was not found?", HexLootHandler.FUNC_AMETHYST_SHARD_REDUCER);
}
return rsr;
}));
}
}