From f426dd5de35aff4c5865e119d4d76dec26f0dc79 Mon Sep 17 00:00:00 2001 From: m1504 Date: Mon, 18 Apr 2022 19:46:48 +0800 Subject: [PATCH] Use new get item way. --- .../java/com/laosun/stackone/StackOneMod.java | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/laosun/stackone/StackOneMod.java b/src/main/java/com/laosun/stackone/StackOneMod.java index 31e8f17..c3f8183 100644 --- a/src/main/java/com/laosun/stackone/StackOneMod.java +++ b/src/main/java/com/laosun/stackone/StackOneMod.java @@ -1,7 +1,10 @@ package com.laosun.stackone; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; +import net.fabricmc.fabric.impl.registry.sync.FabricRegistry; import net.minecraft.item.Item; +import net.minecraft.util.registry.Registry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,14 +18,9 @@ public class StackOneMod implements ModInitializer { @Override public void onInitialize() { - for (int i = 1; ; i++) { + for(Item i : Registry.ITEM){ try { - Item item = Item.byRawId(i); - Item air = Item.byRawId(0); - if (item.equals(air)) { - break; - } - LOGGER.debug(item.getTranslationKey()); + LOGGER.debug(i.getTranslationKey()); Class a = Item.class; Field f2; try { @@ -31,10 +29,31 @@ public void onInitialize() { f2 = a.getDeclaredField("field_8013"); } f2.setAccessible(true); - f2.set(item, 1); + f2.set(i, 1); } catch (Exception e) { e.printStackTrace(); } } +// for (int i = 1; ; i++) { +// try { +// Item item = Item.byRawId(i); +// Item air = Item.byRawId(0); +// if (item.equals(air)) { +// break; +// } +// LOGGER.debug(item.getTranslationKey()); +// Class a = Item.class; +// Field f2; +// try { +// f2 = a.getDeclaredField("maxCount"); +// }catch (NoSuchFieldException e){ +// f2 = a.getDeclaredField("field_8013"); +// } +// f2.setAccessible(true); +// f2.set(item, 1); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } } }