Jump to content

than00ber1

Members
  • Posts

    34
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by than00ber1

  1. I've recently fully finished my first mod for version 1.16.4 and was wondering what is the most efficient way of porting my mod to other game versions.

     

    I suppose you wouldn't create a new project repo to port from 1.16.4 to 1.16.5? Would I need to create a new repo to make the mod compatible with different but still relevant game versions like 1.12.2)? 

     

    It's all a big mystery for me...

     

    PS: I am not sure if this is the correct thread to ask this question.

  2. Ok. I've tried this using ITextComponent instead:

     

    private static ITextComponent fromConfigKey(String key) {
    	return ITextComponent.getTextComponentOrEmpty("config." + key);
    }

     

    This returns the key and not its translatation. I get the same result when calling getString or getUnformattedComponentText.

     

    Maybe this might help too. Heres how I try to register a config:

     

    public class Configs {
    
    	...
    
        public static ForgeConfigSpec.EnumValue<CarveType> CARVE_TYPE;
    
        public Configs(ForgeConfigSpec.Builder forgeConfigBuilder) {
            ConfigBuilder builder = new ConfigBuilder(forgeConfigBuilder);
    
            CARVE_TYPE = builder.defineEnum("carve_type", CarveType.CONNECTED, CarveType.values());
        }
          
        private static class ConfigBuilder {
          
          	private static ForgeConfigSpec.Builder BUILDER;
    
            private ConfigBuilder(ForgeConfigSpec.Builder builder) {
                BUILDER = builder;
            }
          
          	...
          
            public final <V extends Enum<V>> ForgeConfigSpec.EnumValue<V> defineEnum(String key, V defaultValue, V... enums) {
                ITextComponent note = noteFromConfigKey(key);
                return !note.getString().equals("")
                        ? BUILDER.comment(fromConfigKey(key).getString(), note.getString()).defineEnum(key, defaultValue, enums)
                        : BUILDER.comment(fromConfigKey(key).getString()).defineEnum(key, defaultValue, enums);
            }
          
          	private static ITextComponent fromConfigKey(String key) {
          		return ITextComponent.getTextComponentOrEmpty("config." + key);
          	}
          
          	private static ITextComponent noteFromConfigKey(String key) {
                return fromConfigKey(key + ".note");
            }
    	}
    
        public enum CarveType {
            CONNECTED, ALL
        }
    }

     

    This results in a config file like this:

     

    #config.carve_type
    #config.carve_type.note
    #Allowed Values: CONNECTED, ALL
    carve_type = "CONNECTED"

     

    and my en_us.json:

     

    {
    	"config.carve_type": "Block carve type [...] "
    }

     

  3. I've recently moved from 1.12.2 and I am having some trouble getting translations from the JSON lang files.

    Getting translations for items/blocks or enchantments work perfectly but not with custom keys.

     

    I am trying to create translatable components for configs:

     

    In the lang JSON file I created an entry like this,

     

    "config.<config_name>" : "Some english translation text..."

     

    and within the code I call it like this:

     

    private static String fromConfigKey(String key) {
    	return new TranslationTextComponent("config." + key).getUnformattedComponentText();
    }

     

    but returns an empty string.

     

    I have noticed that TranslationTextComponent#getUnformattedComponentText returns an empty string by default, is this something new? Do I have to create my own sub class of TranslationTextComponent which implements this one way or another? 

  4. Alright, I've made some changes to my code and noticed that the precipitation field in the Biome class is final and had to change its modifiers from public final to just public.

     

            private static Field precipitation;
    
            @SubscribeEvent
            public static void onBiomeLoad(BiomeLoadingEvent event) {
                try {
                    precipitation.set(event.getClimate().precipitation, Biome.RainType.SNOW);
                }
                catch (Exception e) {
                    LOGGER.error(e);
                }
            }
    
            static {
                try {
                    precipitation = Biome.Climate.class.getDeclaredField("precipitation");
                    Field mf = Field.class.getDeclaredField("modifiers");
                    mf.setAccessible(true);
                    mf.setInt(precipitation, precipitation.getModifiers() & ~Modifier.FINAL);
    
                    System.out.println(precipitation.getModifiers()); // prints 1 -> public
    
                }
                catch (Exception e) {
                    LOGGER.error(e);
                }
            }

     

     However, an IllegalArgumentException is thrown with message:

     

    Can not set net.minecraft.world.biome.Biome$RainType field net.minecraft.world.biome.Biome$Climate.precipitation to net.minecraft.world.biome.Biome$RainType

     

    I honestly don't understand why this happens. My code seems to make sense (atleast to me)...

     

    Any ideas why that is or how to fix this?

  5. I am trying to change all biome's RainType from RAIN to SNOW.

     

    Following this (old but most recent) post, I figured I should use reflections but I am having some trouble cast from Biome.Builder to Biome with this casting error:

     

    java.lang.ClassCastException: net.minecraft.world.biome.Biome cannot be cast to net.minecraft.world.biome.Biome$Builder

     

    Here is my code:

     

            @SubscribeEvent
            public static void onBiomeRegistry(final RegistryEvent.Register<Biome> event) {
                Set<Map.Entry<RegistryKey<Biome>, Biome>> biomes = event.getRegistry().getEntries();
    
                for (Map.Entry<RegistryKey<Biome>, Biome> biome : biomes) {
                    String name = biome.getValue().getRegistryName().getPath();
                    String method = String.format("make%sBiome", CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name));
                    System.out.println(method);
                    Method builder = null;
                    Biome.Builder biome$builder = null;
    
                    try {
                        builder = ObfuscationReflectionHelper.findMethod(BiomeMaker.class, method);
                        biome$builder = (Biome.Builder) builder.invoke(BiomeMaker.class);
                    }
                    catch (Exception e) {
                        LOGGER.error("Could not get biome builder: %s", e);
                    }
    
                    if (builder != null && biome$builder != null) {
                        Biome newBiome = biome$builder.precipitation(Biome.RainType.SNOW).build();
                        event.getRegistry().register(newBiome);
                        LOGGER.info("NEW BIOME " + newBiome.getPrecipitation());
                    }
                }
            }

     

  6. This is my first post here so I'm not even sure if this is the correct place to address my problem but anyways:

     

    Using DeferredRegisterI was able to successfully override a few block's functionality (the snow block) however, while ingame, the BlockItem does not seem to have been kept from the vanilla game.

     

    Here are some of the side effects I currently have:

    • There are two textureless instances of the snow's BlockItem present within the creative menu (both have the same functionality - behaves like the overriden block)
    • doing /give Dev minecraft:snow gives a textured version of the block (again works as expected)

     

    My understanding is that the reason why this happens is because I have overridden the block and I also need to register a new BlockItem for the new blocks.

     

    This is how I register blocks.

     

    import static com.than00ber.wintersnow.init.AllItems.ITEMS;
    
    public class AllBlocks {
    
        public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Main.MODID);
        public static final DeferredRegister<Block> OVERRIDDEN_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft");
    
        // some cusotm mod blocks fully registered correctly
          
        public static final RegistryObject<Block> BASIC_SNOW = registerBlockOverride(Blocks.SNOW, "snow", BasicSnow::new);
    
        private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block) {
            // register mod blocks - unimportant
        }
    
        private static <T extends Block> RegistryObject<T> registerBlockOverride(Block defaultBlock, String name, Supplier<T> block) {
            RegistryObject<T> reg = OVERRIDDEN_BLOCKS.register(name, block);
            BlockItem blockItem = new BlockItem(defaultBlock, new Item.Properties().group(ItemGroup.BUILDING_BLOCKS));
            ITEMS.register(name, () -> blockItem);
            return reg;
        }
    }

     

    I register the blocks I want to override with a DeferredRegister set with modid minecraft and within my mod's constructor I register the blocks to an event bus:

     

        public Main() {
    
            // Registering blocks
            IEventBus iEventBus = FMLJavaModLoadingContext.get().getModEventBus();
            BLOCKS.register(iEventBus);
            OVERRIDDEN_BLOCKS.register(iEventBus);
            
            // some other stuff - unimportant
        }

     

    I could just get the textures of the block and put them in my mod folder but this seems a bit redundant. Is there any other way I could get the item's normal BlockItem?

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.