Posted April 8, 20187 yr Best Way for Deserializing and Serializing SoundType and BlockMaterials. I want the string to be simple as possible since The end user has to configure the string in order to change a block sound and or block material. I could have a registry between long strings to a readable name for users but, the main goal I hope to achieve is mod support for both block sounds and materials. The issues are: they are not required to be static they are not enums so I can't get an array of them no toString() I could make one using all values but, still can't get around other two issues hard coding only vanilla would make mods incompatible for any modded material and sound type. I see no possible way to grab the object besides iterating through all blocks in post init way after I am suppose to be registering the auto configurable blocks in preinit. Here is what I got so far but, it only supports vanilla period: /** * Only supports vanilla */ public static Material getMat(String s) { s = s.toUpperCase(); if(s.equals("AIR")) return Material.AIR; else if(s.equals("ANVIL")) return Material.ANVIL; else if(s.equals("BARRIER")) return Material.BARRIER; else if(s.equals("CACTUS")) return Material.CACTUS; else if(s.equals("CAKE")) return Material.CAKE; else if(s.equals("CIRCUITS")) return Material.CIRCUITS; else if(s.equals("CARPET")) return Material.CARPET; else if(s.equals("CLAY")) return Material.CLAY; else if(s.equals("CLOTH")) return Material.CLOTH; else if(s.equals("CORAL")) return Material.CORAL; else if(s.equals("CRAFTED_SNOW")) return Material.CRAFTED_SNOW; else if(s.equals("DRAGON_EGG")) return Material.DRAGON_EGG; else if(s.equals("FIRE")) return Material.FIRE; else if(s.equals("GLASS")) return Material.GLASS; else if(s.equals("GOURD")) return Material.GOURD; else if(s.equals("GRASS")) return Material.GRASS; else if(s.equals("GROUND")) return Material.GROUND; else if(s.equals("ICE")) return Material.ICE; else if(s.equals("IRON")) return Material.IRON; else if(s.equals("LAVA")) return Material.LAVA; else if(s.equals("LEAVES")) return Material.LEAVES; else if(s.equals("PACKED_ICE")) return Material.PACKED_ICE; else if(s.equals("PISTON")) return Material.PISTON; else if(s.equals("PLANTS")) return Material.PLANTS; else if(s.equals("PORTAL")) return Material.PORTAL; else if(s.equals("REDSTONE_LIGHT")) return Material.REDSTONE_LIGHT; else if(s.equals("ROCK")) return Material.ROCK; else if(s.equals("SAND")) return Material.SAND; else if(s.equals("SNOW")) return Material.SNOW; else if(s.equals("SPONGE")) return Material.SPONGE; else if(s.equals("STRUCTURE_VOID")) return Material.STRUCTURE_VOID; else if(s.equals("TNT")) return Material.TNT; else if(s.equals("VINE")) return Material.VINE; else if(s.equals("WATER")) return Material.WATER; else if(s.equals("WEB")) return Material.WEB; else if(s.equals("WOOD")) return Material.WOOD; return null; } public static SoundType getSoundType(String s) { s = s.toUpperCase(); if(s.equals("ANVIL")) return SoundType.ANVIL; else if(s.equals("CLOTH")) return SoundType.CLOTH; else if(s.equals("GLASS")) return SoundType.GLASS; else if(s.equals("GROUND")) return SoundType.GROUND; else if(s.equals("LADDER")) return SoundType.LADDER; else if(s.equals("METAL")) return SoundType.METAL; else if(s.equals("PLANT")) return SoundType.PLANT; else if(s.equals("SAND")) return SoundType.SAND; else if(s.equals("SLIME")) return SoundType.SLIME; else if(s.equals("SNOW")) return SoundType.SNOW; else if(s.equals("STONE")) return SoundType.STONE; else if(s.equals("WOOD")) return SoundType.WOOD; return null; } Edited April 8, 20187 yr by jredfox
April 8, 20187 yr Author I don't think there is a way because even if that's possible what is the user suppose to call to identify it? There needs to be a registry between string and material and string and soundtype?
April 8, 20187 yr Author 2 minutes ago, diesieben07 said: Correct, there is no such registry. Should I post a pull to forge even if the soundTypes are client only people should have to register them so other mods know what is and isn't there same with Block Materials. I would also say force resource location if it's going to be global since other mods might come up with the same name like "tropical" material Edited April 8, 20187 yr by jredfox
April 8, 20187 yr Author 2 hours ago, diesieben07 said: I am honestly not quite sure of the benefit, but sure, go ahead. using different block materials and sounds from other mods
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.