-
Posts
444 -
Joined
-
Last visited
-
Days Won
5
Posts posted by kiou.23
-
-
57 minutes ago, ChampionAsh5357 said:
Yes, I would still like to verify that you deferred initialization and registry of the ConfiguredFeature to the common setup event.
And how would I do that?... I think so, but I'm not sure I did because I only had the Features deferred Register in the common setup
public class ModFeatures { public static final ConfiguredFeature<?, ?> ORE_SILVER_CONFIG = Feature.ORE.withConfiguration( new OreFeatureConfig( OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, ModBlocks.SILVER_ORE.get().getDefaultState(), 9 ) ).range(64).square().func_242731_b(20); }
@Mod(TutorialMod.MOD_ID) public class TutorialMod { public static final String MOD_ID = "tutorial"; public static final Logger LOGGER = LogManager.getLogger(); public TutorialMod() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); ModEntities.ENTITY_TYPES.register(modEventBus); ModContainerTypes.CONTAINER_TYPES.register(modEventBus); ModTileEntityTypes.TILE_ENTITY_TYPES.register(modEventBus); ModBlocks.BLOCKS.register(modEventBus); ModItems.ITEMS.register(modEventBus); modEventBus.addListener(this::setup); modEventBus.addListener(this::clientSetup); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { } private void clientSetup(final FMLClientSetupEvent event) { DeferredWorkQueue.runLater(() -> { ScreenManager.registerFactory(ModContainerTypes.TRANSMUTER.get(), TransmuterScreen::new); ScreenManager.registerFactory(ModContainerTypes.CHARGER.get(), ChargerScreen::new); }); } @SubscribeEvent public void onBiomeLoading(final BiomeLoadingEvent biome) { if(biome.getCategory() == Biome.Category.NETHER || biome.getCategory() == Biome.Category.THEEND) return; biome.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES) .add(() -> ModFeatures.ORE_SILVER_CONFIG); } public static final ItemGroup ITEM_GROUP = new ItemGroup(TutorialMod.MOD_ID) { @Override public ItemStack createIcon() { return new ItemStack(ModItems.SILVER_INGOT.get()); } }; }
-
5 minutes ago, I'mBadAtModding said:
how do you get the filler block to be End Stone? I got it working in the overworld, but not in The End
I would think you need to create your own Rule Test, and match it against the End Stone Block, like so:
new BlockMatchRuleTest(Blocks.END_STONE)
and then pass it in the place for the Filler Block Type in the Configured Feature. And in your BiomeLoadingEvent Handler you can test if the Category is equal to Biome.Category.THEEND
-
17 minutes ago, ChampionAsh5357 said:
No, that's not what I said. I said the feature registry is irrelevant, you're not using it. The ConfiguredFeature should be initialized and registered during common setup.
OHHHHH I got it, I don't need the Feature Register at all! I commented it out to check and it still generates, I just need the ConfiguredFeatures and then add them to the biomes in a BiomeLoadingEvent Handler (right?)
I would need the Feature Register if I were to register a whole new type of feature, correct?
-
like this? this doesn't look right at all
public class ModFeatures { public static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, TutorialMod.MOD_ID); public static final ConfiguredFeature<?, ?> ORE_SILVER_CONFIG = Feature.ORE.withConfiguration( new OreFeatureConfig( OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, ModBlocks.SILVER_ORE.get().getDefaultState(), 9 ) ).range(64).square().func_242731_b(20); public static final RegistryObject<Feature<?>> ORE_SILVER = FEATURES.register("ore_silver", () -> ORE_SILVER_CONFIG.feature ); }
@SubscribeEvent public void biomeGeneration(final BiomeLoadingEvent biome) { if(biome.getCategory() == Biome.Category.NETHER || biome.getCategory() == Biome.Category.THEEND) return; biome.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES) .add(() -> ModFeatures.ORE_SILVER_CONFIG); }
sorry for posting repeatedly, I'm just trying to undesrtand how to do this -
Okay, I declared a Deferred Register of type Feature<?> and registered to it like so:
public static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, TutorialMod.MOD_ID); public static final RegistryObject<Feature<?>> ORE_SILVER = FEATURES.register("ore_silver", () -> Feature.ORE.withConfiguration( new OreFeatureConfig( OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, ModBlocks.SILVER_ORE.get().getDefaultState(), 9 ) ).range(64).square().func_242731_b(20).feature );
This doesn't seem to be correct also as for adding the feature to the biome it asks for a configured feature
-
8 hours ago, ChampionAsh5357 said:
The configured feature should be deferred and registered during common setup. In most cases, this would throw an NPE as the registries would not have been populated yet. You're technically cheating by lazily loading the class using a register method for a deferred registry. They should always be attached within the constructor. Just simply register normally in common setup instead of lazily loading a class in a potential error way. Since you're also not creating a feature, it makes no sense to attach the register.
So instead of calling Registry.register, I should call FEATURES.register? and since I'm registering FEATURES in the setup it should be fine, right?
edit: I tried that, but FEATURES.register complains that Feature.ORE.withConfiguration doesn't extends Feature<?>, so how should I go about registering the feature?
-
Could you post the crash log? you can find it on .minecraft/crash-reports
-
1 hour ago, ChampionAsh5357 said:
You should post your repo so that we don't have to guess. If I had to, you're probably create static final variables without considering loading order for the configured feature. In which case, they need to be registered during common setup or at least after placements.
BiomeLoadingEvent holds methods. Read the javadoc and look through the method to find which one is used to add a configured feature.
I managed to get it working! thanks, I want to know if this is the proper way of doing it tho
this is my ModFeatures class:
public class ModFeatures { public static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, TutorialMod.MOD_ID); public static final ConfiguredFeature<?, ?> ORE_SILVER = register("ore_silver", Feature.ORE.withConfiguration( new OreFeatureConfig( OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, ModBlocks.SILVER_ORE.get().getDefaultState(), 9 )).range(64).square().func_242731_b(20) ); private static <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String key, ConfiguredFeature<FC, ?> configuredFeature) { return Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, key, configuredFeature); } }
And this is the main Mod class:
@Mod(TutorialMod.MOD_ID) public class TutorialMod { public static final String MOD_ID = "tutorial"; public static final Logger LOGGER = LogManager.getLogger(); public TutorialMod() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); ModEntities.ENTITY_TYPES.register(modEventBus); ModContainerTypes.CONTAINER_TYPES.register(modEventBus); ModTileEntityTypes.TILE_ENTITY_TYPES.register(modEventBus); ModBlocks.BLOCKS.register(modEventBus); ModItems.ITEMS.register(modEventBus); modEventBus.addListener(this::setup); modEventBus.addListener(this::doClientStuff); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); ModFeatures.FEATURES.register(modEventBus); } private void doClientStuff(final FMLClientSetupEvent event) { DeferredWorkQueue.runLater(() -> { ScreenManager.registerFactory(ModContainerTypes.TRANSMUTER.get(), TransmuterScreen::new); ScreenManager.registerFactory(ModContainerTypes.CHARGER.get(), ChargerScreen::new); }); } @SubscribeEvent public void biomeGeneration(final BiomeLoadingEvent event) { event.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES) .add(() -> ModFeatures.ORE_SILVER); } public static final ItemGroup ITEM_GROUP = new ItemGroup(TutorialMod.MOD_ID) { @Override public ItemStack createIcon() { return new ItemStack(ModItems.SILVER_INGOT.get()); } }; }
Additionally, I would like to know how this piece of code works, I have a vgue idea, but I basically just copied it from the Iron Ore Feature
Feature.ORE.withConfiguration( new OreFeatureConfig( OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, ModBlocks.SILVER_ORE.get().getDefaultState(), 9 )).range(64).square().func_242731_b(20)
-
17 hours ago, ChampionAsh5357 said:
1. Create a ConfiguredFeature and register it (look at the Features class for examples).
2. Attach it via BiomeLoadingEvent (read the javadocs on the event as applicable to your situation).
I have the same questions. From what I gathered from this reply I made a ModFeatures class, where I register the ConfiguredFeatures, however how do I attach it to the BiomeLoadingEvent? I tried using the deferred registries the same way I did for blocks and items but it errors out because the block to generate isn't registered yet, even tho I am calling the register method in the Features Deferred Register after the Blocks Deferred Register
-
1
-
-
2 hours ago, poopoodice said:
Minecraft.getInstance().player.sendChatMessage("Block Placed with CHARGE: " + (Integer)blockState.get(CHARGE));
This will crash on server https://mcforge.readthedocs.io/en/latest/concepts/sides/, use the player provided instead.
You need to show more of your code
I was running Client, and I just added that for debugging purposes, is it still the cause of the error?
and what other part of the code I should add? There isn't much else, the problem I thought would be in the ExplodingBlock class
-
I'm tinkering with some stuff while trying to learn modding, I made a class for a Block that extends net.minecraft.Block, but I get an error when registering it
This is the block class:
public class ExplodingBlock extends Block { public ExplodingBlock(Properties props) { super(props); this.setDefaultState( this.stateContainer.getBaseState() .with(CHARGE, 0) ); Minecraft.getInstance().player.sendChatMessage("Block Placed with CHARGE: 0"); } static final IntegerProperty CHARGE = IntegerProperty.create("charge", 0, 5); @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> container) { super.fillStateContainer(container); container.add(new Property[]{CHARGE}); } public ActionResultType onBlockActivated(BlockState blockState, World world, BlockPos blockPos, PlayerEntity player, Hand hand, BlockRayTraceResult rayRes) { world.setBlockState(blockPos, blockState.with(CHARGE, (Integer)blockState.get(CHARGE) + 1)); Minecraft.getInstance().player.sendChatMessage("Block Placed with CHARGE: " + (Integer)blockState.get(CHARGE)); return ActionResultType.SUCCESS; } }
And this is the code for registering it:
public static final RegistryObject<ExplodingBlock> EXPLODING_BLOCK = register("exploding_block", () -> new ExplodingBlock(AbstractBlock.Properties.create(Material.TNT) .hardnessAndResistance(3, 10) .sound(SoundType.STONE)) );
I am registering other blocks that use simply RegistryObject<Block>, and the supplier is a new Block(), and they work. The code also worked when I changed the registering to Use of the Block class instead of the inheriting ExplondingBlock class, but without the functionally I wanted, of course.
I get the following error in the minecraft window after loading:
Tutorial Mod (tutorial) encountered an error during the load_registries event phase Tutorial Mod (tutorial) encountered an error during the error event phase java.lang.NullPointerException: Registry Object not present: tutorial:exploding_block
-
32 minutes ago, TheGreyGhost said:
>Additionnaly, is there a Data Generator to generate Entity models?
Try BlockBench, it is quite awesome
This is going to be REALy useful, thanks!!
But then... I know there are Deferred Registries for Entities, I'm just not getting EntityType.Builder.create to work I think... Still thanks tho
I'm going to stick sctrictly to deferred registries, they seem far easier to write
-
I have an Item (DynamiteStickItem) that when used spawns an entity (DynamiteEntity) that extends ProjectileTileEntity.
if (!worldIn.isRemote) { DynamiteEntity dynamiteEntity = new DynamiteEntity(worldIn, player); dynamiteEntity.setItem(currentItemStack); dynamiteEntity.func_234612_a_(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f); worldIn.addEntity(dynamiteEntity); }
However, the Java compiler seems to have a problem with the constructors. At first, in the DynamiteEntity, I had the following constructor:
public DynamiteEntity(World world, PlayerEntity player) { super(EntityTypes.SNOWBALL, player, world); }
Then when I used the Item, the summoned entity had the snowball texture. I figured I had to register my own EntityType, and I'm trying to do so with the Deferred Registries.
public static final RegistryObject<EntityType<DynamiteEntity>> DYNAMITE_ENTITY = RegistryHandler.ENTITIES.register("dynamite_entity", () -> EntityType.Builder.create(DynamiteEntity::new, EntityClassification.MISC) .size(0.25f, 0.25f) .build("dynamite_entity") );
(I don't know if I'm missing something when passing the Supplier using EntityType.Builder.create method, I haven't found much resources about registering entities)
However, The EntityType.Builder.create complained about the constructor, so I looked at the code for the Snowball constructors and added the following to the DynamiteEntity class:
public DynamiteEntity(EntityType<? extends DynamiteEntity> entity, World world) { super(entity, world); }
Then the EntityType.Builder.create is not being able to resolve the constructor for 'DynamiteEntity'. I Tried removing the initial constructor (and updating the code in DynamiteStickItem to use only the construcor that uses EntityType<? extends DynamiteEntity>), the EntityType.Builder.create then worked, but the Item wouldn't spawn the Entity, and It wasn't textures when I tried spawning it using commands...
What am I doing wrong?
Additionnaly, is there a Data Generator to generate Entity models?
-
I've been trying to get into forge modding for minecraft for years now, and I've always been having a hard time. Mainly because it's so hard to find good resources to study through, they are mostly incomplete or outdated...
I've found a couple of good videos on SilentChaos512 youtube channel, but it seems he doesn't update very frequently.
I've tried making some stuff for myself, and from studying the code from the snowball and the TNTEntity I managed to make a throwable dynamite stick (very cliche, I know), but I still having a hard time on using the Deferred registry to register Entities, and there are still so much knowlodge lacking that I just can't find consistence sources on.
What sources did you use to learn? and what are some good updated sources? (I've read the forge docs, they seem very incomplete and still attached to some stuff from older versions).
[1.16.4] How do I make my ore generate thru the world?
in Modder Support
Posted
Like so?