Skip to content

Commit

Permalink
use AW instead of reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
RawDiamondMC committed Aug 8, 2024
1 parent 4b82a66 commit 3adf4d4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
3 changes: 3 additions & 0 deletions registry-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ base.archivesName = rootProject.name + "-registry"

dependencies {
moduleImplementation(project(":base-common"))
}
loom {
accessWidenerPath = file("src/main/resources/kessoku_registry.accesswidener")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package band.kessoku.lib.registry.api;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -169,15 +167,9 @@ public static void setFuelTime(ItemConvertible item, int cookTime) {
* @return The fuel time.
*/
public static <T extends AbstractFurnaceBlock> int getFuelTime(T block, ItemStack stack) {
try {
BlockEntity entity = block.createBlockEntity(null, null);
if (!(entity instanceof AbstractFurnaceBlockEntity)) return 0;
Method method = AbstractFurnaceBlockEntity.class.getDeclaredMethod("getFuelTime", ItemStack.class);
method.setAccessible(true);
return (int) method.invoke(entity, stack);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException(e);
}
BlockEntity entity = block.createBlockEntity(null, null);
if (!(entity instanceof AbstractFurnaceBlockEntity)) return 0;
return ((AbstractFurnaceBlockEntity) entity).getFuelTime(stack);
}

public record ItemWithData(ComponentMap componentMap, ItemConvertible item) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
accessWidener v2 named
accessible method net/minecraft/block/entity/AbstractFurnaceBlockEntity getFuelTime (Lnet/minecraft/item/ItemStack;)I

0 comments on commit 3adf4d4

Please sign in to comment.