Skip to content

Commit

Permalink
Udpate to latest Neo, Fabric and Parchment
Browse files Browse the repository at this point in the history
 - Update to latest NeoForge, fixing issues with config API changes.
   Closes #1903.
 - Update to latest Fabric, switching to the ender pearl conventional
   tag, and new loot API.
  • Loading branch information
SquidDev committed Jul 28, 2024
1 parent 2c740bb commit 2765abf
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 30 deletions.
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
# Minecraft
# MC version is specified in gradle.properties, as we need that in settings.gradle.
# Remember to update corresponding versions in fabric.mod.json/neoforge.mods.toml
fabric-api = "0.100.3+1.21"
fabric-api = "0.100.7+1.21"
fabric-loader = "0.15.11"
neoForge = "21.0.42-beta"
neoForge = "21.0.143"
neoForgeSpi = "8.0.1"
mixin = "0.8.5"
parchment = "2024.06.16"
parchmentMc = "1.20.6"
parchment = "2024.07.28"
parchmentMc = "1.21"
yarn = "1.21+build.1"

# Core dependencies (these versions are tied to the version Minecraft uses)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private ItemStackComponentizationFixMixin(Schema outputSchema, boolean changesTy
}

@Inject(method = "fixItemStack", at = @At("TAIL"))
@SuppressWarnings("UnusedMethod")
@SuppressWarnings("unused")
private static void fixItemStack(ItemStackComponentizationFix.ItemStackData data, Dynamic<?> ops, CallbackInfo ci) {
ComponentizationFixers.fixItemComponents(data, ops);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ The maximum size (in bytes) that a computer can upload in a single request. This
);
}

public static UnmodifiableConfig newRule() {
return makeRule(config -> {
config.add("host", "example.com");
config.add("action", Action.DENY.name().toLowerCase(Locale.ROOT));
});
}

private static UnmodifiableConfig makeRule(Consumer<CommentedConfig> setup) {
var config = InMemoryCommentedFormat.defaultInstance().createConfig(LinkedHashMap::new);
setup.accept(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void pop() {

public abstract ConfigFile.Value<Integer> defineInRange(String path, int defaultValue, int min, int max);

public abstract <T> ConfigFile.Value<List<? extends T>> defineList(String path, List<? extends T> defaultValue, Predicate<Object> elementValidator);
public abstract <T> ConfigFile.Value<List<? extends T>> defineList(String path, List<? extends T> defaultValue, Supplier<T> newValue, Predicate<Object> elementValidator);

public abstract <V extends Enum<V>> ConfigFile.Value<V> defineEnum(String path, V defaultValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Methods in this list can either be a whole group of methods (computercraft:inven
or a single method (computercraft:inventory#pushItems).
""")
.worldRestart()
.defineList("disabled_generic_methods", List.of(), x -> x instanceof String);
.defineList("disabled_generic_methods", List.of(), () -> "", x -> x instanceof String);
}

{
Expand Down Expand Up @@ -214,7 +214,7 @@ or a single method (computercraft:inventory#pushItems).
- "max_websocket_message" (optional): The maximum size (in bytes) that a computer can send or
receive in one websocket packet.
- "use_proxy" (optional): Enable use of the HTTP/SOCKS proxy if it is configured.""")
.defineList("rules", AddressRuleConfig.defaultRules(), x -> x instanceof UnmodifiableConfig);
.defineList("rules", AddressRuleConfig.defaultRules(), AddressRuleConfig::newRule, x -> x instanceof UnmodifiableConfig);

httpMaxRequests = builder
.comment("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
* A custom version of {@link ShapedRecipe}, which can be converted to and from a {@link ShapedRecipeSpec}.
*/
public abstract class CustomShapedRecipe extends ShapedRecipe {
private final ShapedRecipePattern pattern;
private final ShapedRecipePattern shapedPattern;
private final ItemStack result;

public CustomShapedRecipe(ShapedRecipeSpec recipe) {
super(recipe.properties().group(), recipe.properties().category(), recipe.pattern(), recipe.result(), recipe.properties().showNotification());
this.pattern = recipe.pattern();
this.shapedPattern = recipe.pattern();
this.result = recipe.result();
}

public final ShapedRecipeSpec toSpec() {
return new ShapedRecipeSpec(RecipeProperties.of(this), pattern, result);
return new ShapedRecipeSpec(RecipeProperties.of(this), shapedPattern, result);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.fabricmc.fabric.api.loot.v3.LootTableEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
Expand Down Expand Up @@ -122,7 +122,7 @@ public static void init() {
PlayerBlockBreakEvents.BEFORE.register(FabricCommonHooks::onBlockDestroy);
UseBlockCallback.EVENT.register(FabricCommonHooks::useOnBlock);

LootTableEvents.MODIFY.register((id, tableBuilder, source) -> {
LootTableEvents.MODIFY.register((id, tableBuilder, source, registries) -> {
var pool = CommonHooks.getExtraLootPool(id);
if (pool != null) tableBuilder.withPool(pool);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -203,7 +204,7 @@ public Value<Integer> defineInRange(String path, int defaultValue, int min, int
}

@Override
public <T> Value<List<? extends T>> defineList(String path, List<? extends T> defaultValue, Predicate<Object> elementValidator) {
public <T> Value<List<? extends T>> defineList(String path, List<? extends T> defaultValue, Supplier<T> newValue, Predicate<Object> elementValidator) {
var fullPath = getFullPath(path);
spec.defineList(fullPath, defaultValue, elementValidator);
return defineValue(fullPath, takeComment(), defaultValue, Config::getOrElse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public RecipeIngredients getRecipeIngredients() {
Ingredient.of(ConventionalItemTags.STORAGE_BLOCKS_GOLD),
Ingredient.of(ConventionalItemTags.IRON_INGOTS),
Ingredient.of(ConventionalItemTags.DYES),
Ingredient.of(Items.ENDER_PEARL),
Ingredient.of(ConventionalItemTags.ENDER_PEARLS),
Ingredient.of(ConventionalItemTags.WOODEN_CHESTS)
);
}
Expand Down
2 changes: 1 addition & 1 deletion projects/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"depends": {
"fabricloader": ">=0.15.10",
"fabric-api": ">=0.100.3",
"fabric-api": ">=0.100.5",
"minecraft": "=1.21"
},
"accessWidener": "computercraft.accesswidener"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package dan200.computercraft;

import com.electronwill.nightconfig.core.file.FileConfig;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.ForgeComputerCraftAPI;
import dan200.computercraft.api.detail.ForgeDetailRegistries;
Expand Down Expand Up @@ -171,8 +170,7 @@ public static void sync(ModConfigEvent.Reloading event) {
private static void syncConfig(ModConfig config) {
if (!config.getModId().equals(ComputerCraftAPI.MOD_ID)) return;

var path = config.getConfigData() instanceof FileConfig fileConfig ? fileConfig.getNioPath() : null;

var path = config.getFullPath();
if (config.getType() == ModConfig.Type.SERVER && ((ForgeConfigFile) ConfigSpec.serverSpec).spec().isLoaded()) {
ConfigSpec.syncServer(path);
} else if (config.getType() == ModConfig.Type.CLIENT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -105,9 +107,9 @@ public ConfigFile.Value<Integer> defineInRange(String path, int defaultValue, in
}

@Override
public <T> ConfigFile.Value<List<? extends T>> defineList(String path, List<? extends T> defaultValue, Predicate<Object> elementValidator) {
public <T> ConfigFile.Value<List<? extends T>> defineList(String path, List<? extends T> defaultValue, Supplier<T> newValue, Predicate<Object> elementValidator) {
translation(path);
return defineValue(builder.defineList(path, defaultValue, elementValidator));
return defineValue(builder.defineList(path, defaultValue, newValue, elementValidator));
}

@Override
Expand Down Expand Up @@ -168,12 +170,12 @@ public T get() {

@Override
public String translationKey() {
return spec().getTranslationKey();
return Objects.requireNonNull(spec().getTranslationKey(), "No comment for value");
}

@Override
public String comment() {
return spec().getComment();
return Objects.requireNonNull(spec().getComment(), "No comment for value");
}
}
}

0 comments on commit 2765abf

Please sign in to comment.