diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/AbstractConfig.java b/config/common/src/main/java/band/kessoku/lib/config/api/AbstractConfig.java index 2c3041bf..416d6827 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/AbstractConfig.java +++ b/config/common/src/main/java/band/kessoku/lib/config/api/AbstractConfig.java @@ -143,6 +143,8 @@ public void reset() { List fields = new ArrayList<>(); for (Field declaredField : this.getClass().getDeclaredFields()) { + declaredField.setAccessible(true); + final boolean flag0 = declaredField.getDeclaringClass().isAssignableFrom(ConfigValue.class); final boolean flag1 = Modifier.isPublic(declaredField.getModifiers()); final boolean flag2 = !Modifier.isStatic(declaredField.getModifiers()); @@ -163,6 +165,7 @@ public ImmutableList getValidCategories() { List fields = new ArrayList<>(); for (Field declaredField : this.getClass().getDeclaredFields()) { + declaredField.setAccessible(true); final boolean flag0 = declaredField.getDeclaringClass().isAssignableFrom(AbstractConfig.class); final boolean flag1 = Modifier.isPublic(declaredField.getModifiers()); @@ -178,6 +181,7 @@ public ImmutableList getValidCategories() { private ImmutableList getValidFields() { ImmutableList.Builder builder = ImmutableList.builder(); for (Field declaredField : this.getClass().getDeclaredFields()) { + declaredField.setAccessible(true); final boolean flag0 = declaredField.getDeclaringClass().isAssignableFrom(AbstractConfig.class); final boolean flag1 = declaredField.getDeclaringClass().isAssignableFrom(ConfigValue.class); @@ -196,6 +200,7 @@ private Map serialize() { ImmutableMap.Builder builder = ImmutableMap.builder(); for (Field field : this.getValidFields()) { field.setAccessible(true); + final String name = field.isAnnotationPresent(Name.class) ? field.getAnnotation(Name.class).value() : field.getName(); final String[] comments = field.isAnnotationPresent(Comments.class) ? (String[]) Arrays.stream(field.getAnnotation(Comments.class).value()).map(Comment::value).toArray() : new String[0]; diff --git a/keybind/neo/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java b/keybind/neo/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java index 09c9e343..6e34c8ce 100644 --- a/keybind/neo/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java +++ b/keybind/neo/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java @@ -27,13 +27,15 @@ import java.util.List; import java.util.Map; -import java.util.Optional; @AutoService(KeyBindRegister.class) public class KeyBindRegisterImpl implements KeyBindRegister { private static final List KEY_BINDINGS = new ReferenceArrayList<>(); private static boolean processed; + /* Amarok Note: + Maybe Object2IntMap ...? + */ private static Map getCategoryMap() { return KeyBindingAccessor.kessoku$getCategoryMap(); } @@ -46,9 +48,8 @@ public boolean addCategory(String categoryTranslationKey) { return false; } - Optional largest = map.values().stream().max(Integer::compareTo); - int largestInt = largest.orElse(0); - map.put(categoryTranslationKey, largestInt + 1); + final int largest = map.values().stream().max(Integer::compareTo).orElse(0); + map.put(categoryTranslationKey, largest + 1); return true; } diff --git a/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java b/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java index ad676b8d..2b202b06 100644 --- a/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java +++ b/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java @@ -25,21 +25,12 @@ public ModDependencyInfoImpl(IModInfo.ModVersion modVersion) { } @Override public DependencyKind getKind() { - switch (value.getType()) { - case OPTIONAL -> { - return DependencyKind.OPTIONAL; - } - case REQUIRED -> { - return DependencyKind.DEPENDS; - } - case DISCOURAGED -> { - return DependencyKind.CONFLICTS; - } - case INCOMPATIBLE -> { - return DependencyKind.BREAKS; - } - } - return null; + return switch (value.getType()) { + case OPTIONAL -> DependencyKind.OPTIONAL; + case REQUIRED -> DependencyKind.DEPENDS; + case DISCOURAGED -> DependencyKind.CONFLICTS; + case INCOMPATIBLE -> DependencyKind.BREAKS; + }; } @Override diff --git a/registry/common/src/main/java/band/kessoku/lib/registry/api/FuelRegistry.java b/registry/common/src/main/java/band/kessoku/lib/registry/api/FuelRegistry.java index d8b3923b..4c829c32 100644 --- a/registry/common/src/main/java/band/kessoku/lib/registry/api/FuelRegistry.java +++ b/registry/common/src/main/java/band/kessoku/lib/registry/api/FuelRegistry.java @@ -17,9 +17,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; -import net.minecraft.block.AbstractFurnaceBlock; import net.minecraft.block.entity.AbstractFurnaceBlockEntity; -import net.minecraft.block.entity.BlockEntity; import net.minecraft.component.ComponentMap; import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; @@ -28,7 +26,6 @@ import net.minecraft.recipe.RecipeType; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.TagKey; -import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -178,15 +175,11 @@ public static void setFuelTime(ItemConvertible item, int cookTime) { } /** - * @param block the block which acts like a furnace * @return The fuel time. */ - public static int getFuelTime(T block, ItemStack stack) { - BlockEntity entity = block.createBlockEntity((BlockPos) BlockPos.ZERO, block.getDefaultState()); - if (!(entity instanceof AbstractFurnaceBlockEntity)) return 0; - int fuelTime = ((AbstractFurnaceBlockEntity) entity).getFuelTime(stack); - entity.markRemoved(); - return fuelTime; + public static int getFuelTime(ItemStack stack) { + final var fuelMap = AbstractFurnaceBlockEntity.createFuelTimeMap(); + return fuelMap.getOrDefault(stack.getItem(), 0); } public record ItemWithData(ComponentMap componentMap, ItemConvertible item) { diff --git a/registry/neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java b/registry/neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java index 278a47ae..af56993b 100644 --- a/registry/neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java +++ b/registry/neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java @@ -27,18 +27,18 @@ import net.neoforged.neoforge.event.furnace.FurnaceFuelBurnTimeEvent; import net.neoforged.neoforge.registries.RegisterEvent; +import java.util.Objects; +import java.util.Optional; + @Mod(KessokuRegistry.MOD_ID) public class KessokuRegistryEntrypoint { public KessokuRegistryEntrypoint(IEventBus modEventBus) { ModUtils.getLogger().info(KessokuRegistry.MARKER, "KessokuLib-Registry is loaded!"); NeoEventUtils.registerEvent(modEventBus, RegisterEvent.class, RegistryImpl::onRegister); NeoEventUtils.registerEvent(NeoForge.EVENT_BUS, FurnaceFuelBurnTimeEvent.class, event -> { - ItemStack stack = event.getItemStack(); - RecipeType recipeType = event.getRecipeType(); - Integer burnTime; - if (recipeType != null) burnTime = FuelRegistry.of(recipeType).get(stack); - else burnTime = FuelRegistry.of(RecipeType.SMELTING).get(stack); - if (burnTime != null) event.setBurnTime(burnTime); + final ItemStack stack = event.getItemStack(); + final RecipeType recipeType = Objects.requireNonNullElse(event.getRecipeType(), RecipeType.SMELTING); + Optional.ofNullable(FuelRegistry.of(recipeType).get(stack)).ifPresent(event::setBurnTime); }); } } diff --git a/registry/neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java b/registry/neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java index 70d0e7dd..2a352302 100644 --- a/registry/neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java +++ b/registry/neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java @@ -17,12 +17,13 @@ import band.kessoku.lib.registry.api.Registry; import com.google.auto.service.AutoService; +import com.google.common.collect.Maps; import net.minecraft.util.Identifier; import net.neoforged.neoforge.registries.RegisterEvent; import org.jetbrains.annotations.ApiStatus; -import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; @AutoService(Registry.class) @@ -39,12 +40,15 @@ public static void onRegister(RegisterEvent event) { @Override public T registerInternal(net.minecraft.registry.Registry registry, Identifier id, T entry) { - if (registered) + if (registered) { throw new IllegalStateException("Cannot register new entries after net.neoforged.neoforge.registries.RegisterEvent has been fired."); - if (!registries.containsKey(registry)) registries.put(registry, new HashMap<>()); - if (registries.get(registry).putIfAbsent(id, entry) != null) { + } + + final var map = Objects.requireNonNull(registries.putIfAbsent(registry, Maps.newHashMap())); + if (map.putIfAbsent(id, entry) != null) { throw new IllegalArgumentException("Duplicate registration " + id.toString()); } + return entry; } }