Drachenbauer Geschrieben 18. März 2020 Share Geschrieben 18. März 2020 (bearbeitet) Hallo Ich versuche zur zeit, Bei der nutzung von DeferredRegister die Instanzen von RegistryObject per for-loop in einer ArrayList<RegistryObject<FlowerPotBlock>> zu registrieren. Ich habe eine Mod mit Blumentöüfen in den 16 Minecraft-Standardfarben (Beton-Texturen) erstellt. 16 Topffarben x 25 Pflanzen, die in Töpfe passen + 16 leere Töpfe ergibt 416 neue Blöcke, die Registriert werden müssen. Im Moment habe ich daher eine ziemlich lange Klasse voll instanzen von RegistryObject. Dort würde ich daher gerne die Menge an Code reduzieren. Mein derzeitiger Versuch: public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, Reference.MOD_ID); private static final Supplier<Block> AIR_SUPPLIER = () -> Blocks.AIR; public static final ArrayList<Supplier<Block>> PLANT_SUPPLIERS = new ArrayList<Supplier<Block>>(Arrays.asList(() -> Blocks.ACACIA_SAPLING, () -> Blocks.ALLIUM, () -> Blocks.AZURE_BLUET, () -> Blocks.BAMBOO, () -> Blocks.BIRCH_SAPLING, () -> Blocks.BLUE_ORCHID, () -> Blocks.BROWN_MUSHROOM, () -> Blocks.CACTUS, () -> Blocks.CORNFLOWER, () -> Blocks.DANDELION, () -> Blocks.DARK_OAK_SAPLING, () -> Blocks.DEAD_BUSH, () -> Blocks.FERN, () -> Blocks.JUNGLE_SAPLING, () -> Blocks.LILY_OF_THE_VALLEY, () -> Blocks.OAK_SAPLING, () -> Blocks.ORANGE_TULIP, () -> Blocks.OXEYE_DAISY, () -> Blocks.PINK_TULIP, () -> Blocks.POPPY, () -> Blocks.RED_MUSHROOM, () -> Blocks.RED_TULIP, () -> Blocks.SPRUCE_SAPLING, () -> Blocks.WHITE_TULIP, () -> Blocks.WITHER_ROSE)); public static final ArrayList<String> COLORS = new ArrayList<String>(Arrays.asList("black", "blue", "brown", "cyan", "gray", "green", "light_blue", "light_gray", "lime", "magenta", "orange", "pink", "purple", "red", "white", "yellow")); public static final ArrayList<RegistryObject<FlowerPotBlock>> EMPTY_FLOWER_POT_REGISTRIES = new ArrayList<RegistryObject<FlowerPotBlock>>(); public static final ArrayList<Supplier<FlowerPotBlock>> EMPTY_FLOWER_POT_SUPPLIERS = new ArrayList<Supplier<FlowerPotBlock>>(); public static final ArrayList<FlowerPotBlock> EMPTY_FLOWER_POTS = new ArrayList<FlowerPotBlock>(); public static final ArrayList<RegistryObject<FlowerPotBlock>> FULL_FLOWER_POT_REGISTRIES = new ArrayList<RegistryObject<FlowerPotBlock>>(); public static final ArrayList<Supplier<FlowerPotBlock>> FULL_FLOWER_POT_SUPPLIERS = new ArrayList<Supplier<FlowerPotBlock>>(); public static final ArrayList<FlowerPotBlock> FULL_FLOWER_POTS = new ArrayList<FlowerPotBlock>(); private static int i; private static int j; static { i = 0; for(String color : COLORS) { EMPTY_FLOWER_POT_REGISTRIES.add(BLOCKS.register(color + "_flower_pot", () -> new FlowerPotBlock(null, AIR_SUPPLIER, Block.Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0f).notSolid()))); EMPTY_FLOWER_POT_SUPPLIERS.add(() -> EMPTY_FLOWER_POT_REGISTRIES.get(i).get()); j = 0; for(Supplier<Block> plant_supplier : PLANT_SUPPLIERS) { String plant = plant_supplier.get().getRegistryName().getPath(); FULL_FLOWER_POT_REGISTRIES.add(BLOCKS.register(color + "_potted_" + plant, () -> new FlowerPotBlock(EMPTY_FLOWER_POT_SUPPLIERS.get(i), plant_supplier, Block.Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0f).notSolid()))); FULL_FLOWER_POT_SUPPLIERS.add(() -> FULL_FLOWER_POT_REGISTRIES.get(j).get()); j++; } i++; } } Wenn ich mit diesem Code einen Testlauf starte, kommen Fehler des typs: Zitat Object not present in der Konsole an der nächsten Stelle, wo eine Code-Zeile auf den registrierten Block zugreifen will (außer dem Erstellen der Supplier-Listen im gezeigten Code, dort entsteht kein Fehler). Zum Beispiel, wenn ich die im code angelegten, aber ungenutzten Listen für den Typ FlowerPotBlock mit den Blöcken aus den Registrierungs-Listen füllen will (Zeilen im jeweiligen for-loop-Bereich vom gezeigten code hinzufügen): EMPTY_FLOWER_POTS.add(EMPTY_FLOWER_POT_REGISTRIES.get(i).get()); FULL_FLOWER_POTS.add(FULL_FLOWER_POT_REGISTRIES.get(j).get()); Dann wird der Fehler für diese Zeile angezeigt. Wieso werden die Blöcke in so einer Liste nicht richtig registriert? Gibt es irgendwas, das ich ändern muss, damit es doch in so einer Struktur funktioniert? bearbeitet 19. März 2020 von Drachenbauer Link zu diesem Kommentar Auf anderen Seiten teilen More sharing options...
Empfohlene Beiträge
Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren
Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können
Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!
Neues Benutzerkonto erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde dich hier an.
Jetzt anmelden