Custom Features

Started by Jarglo33 on

Topic category: User side tutorials

Last seen on 05:58, 24. Jan 2021
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Custom Features

So I've Been working on custom features and i thought that it would be nice for me to share. So I will give the feature code for mushrooms in custom biomes. this go inside the custom biome java.

//import your custom blocks before running. and these

import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.block.HugeMushroomBlock;
import net.minecraft.block.material.Material;
import net.minecraft.block.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Block;
import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.feature.AbstractBigMushroomFeature;
import net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.IWorldGenerationReader;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.GenerationSettings;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.placement.FrequencyConfig;
import net.minecraft.world.gen.feature.BigMushroomFeatureConfig;
import com.mojang.datafixers.Dynamic;
import java.util.Random;
import java.util.function.Function;
import net.minecraft.block.HugeMushroomBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;

// this is the blockstate variables for HugeMushroomBlock modeled blocks, paste under static class CustomBiome and before public CustomBiome()

private static final BlockState MUSHROOM_BLOCK = MirasmiusMushroomBlockBlock.block.getDefaultState().with(HugeMushroomBlock.DOWN, Boolean.valueOf(false));
private static final BlockState MUSHROOM_STEM = Blocks.MUSHROOM_STEM.getDefaultState().with(HugeMushroomBlock.UP, Boolean.valueOf(false)).with(HugeMushroomBlock.DOWN, Boolean.valueOf(false));

// how to make the feature spawn, paste this under the Default Biome Features

addFeature(GenerationStage.Decoration.VEGETAL_DECORATION,  new MirasmiusMushroomFeature(BigMushroomFeatureConfig::deserialize)
					.withConfiguration(new BigMushroomFeatureConfig(new SimpleBlockStateProvider(MUSHROOM_BLOCK), new SimpleBlockStateProvider(MUSHROOM_STEM), 2))
					.withPlacement(Placement.COUNT_HEIGHTMAP.configure(new FrequencyConfig(1))));

//this is the custom feature for the big red mushroom shape, replace UtoreMushroomGrassBlock with the grass for your biome and UtoreDirtBlock with the custom dirt from your biome

static class MirasmiusMushroomFeature extends AbstractBigMushroomFeature{
		public MirasmiusMushroomFeature(Function<Dynamic<?>, ? extends BigMushroomFeatureConfig> config) {
			super(config);
		}

		protected boolean func_227209_a_(IWorld p_227209_1_, BlockPos p_227209_2_, int p_227209_3_, BlockPos.Mutable p_227209_4_, BigMushroomFeatureConfig p_227209_5_) {
	      int i = p_227209_2_.getY();
	      if (i >= 1 && i + p_227209_3_ + 1 < p_227209_1_.getMaxHeight()) {
	        Block ground = p_227209_1_.getBlockState(p_227209_2_.add(0, -1, 0)).getBlock();
			Block ground2 = p_227209_1_.getBlockState(p_227209_2_.add(0, -2, 0)).getBlock();
			if (!((ground == UtoreMushroomGrassBlock.block.getDefaultState().getBlock()
					|| ground == UtoreDirtBlock.block.getDefaultState().getBlock())
					&& (ground2 == UtoreMushroomGrassBlock.block.getDefaultState().getBlock()
					|| ground2 == UtoreDirtBlock.block.getDefaultState().getBlock()))){
						return false;
	         } else {
	            for(int j = 0; j <= p_227209_3_; ++j) {
	               int k = this.func_225563_a_(-1, -1, p_227209_5_.field_227274_c_, j);
	
	               for(int l = -k; l <= k; ++l) {
	                  for(int i1 = -k; i1 <= k; ++i1) {
	                     BlockState blockstate = p_227209_1_.getBlockState(p_227209_4_.setPos(p_227209_2_).move(l, j, i1));
	                     if (!blockstate.isAir(p_227209_1_, p_227209_4_) && !blockstate.isIn(BlockTags.LEAVES)) {
	                        return false;
	                     }
	                  }
	               }
	            }
	
	            return true;
	         }
	      } else {
	         return false;
	      }
	   }
		
		 protected void func_225564_a_(IWorld p_225564_1_, Random p_225564_2_, BlockPos p_225564_3_, int p_225564_4_, BlockPos.Mutable p_225564_5_, BigMushroomFeatureConfig p_225564_6_) {
	      for(int i = p_225564_4_ - 3; i <= p_225564_4_; ++i) {
	         int j = i < p_225564_4_ ? p_225564_6_.field_227274_c_ : p_225564_6_.field_227274_c_ - 1;
	         int k = p_225564_6_.field_227274_c_ - 2;
	
	         for(int l = -j; l <= j; ++l) {
	            for(int i1 = -j; i1 <= j; ++i1) {
	               boolean flag = l == -j;
	               boolean flag1 = l == j;
	               boolean flag2 = i1 == -j;
	               boolean flag3 = i1 == j;
	               boolean flag4 = flag || flag1;
	               boolean flag5 = flag2 || flag3;
	               if (i >= p_225564_4_ || flag4 != flag5) {
	                  p_225564_5_.setPos(p_225564_3_).move(l, i, i1);
	                  if (p_225564_1_.getBlockState(p_225564_5_).canBeReplacedByLeaves(p_225564_1_, p_225564_5_)) {
	                     this.setBlockState(p_225564_1_, p_225564_5_, p_225564_6_.field_227272_a_.getBlockState(p_225564_2_, p_225564_3_).with(HugeMushroomBlock.UP, Boolean.valueOf(i >= p_225564_4_ - 1)).with(HugeMushroomBlock.WEST, Boolean.valueOf(l < -k)).with(HugeMushroomBlock.EAST, Boolean.valueOf(l > k)).with(HugeMushroomBlock.NORTH, Boolean.valueOf(i1 < -k)).with(HugeMushroomBlock.SOUTH, Boolean.valueOf(i1 > k)));
	                  }
	               }
	            }
	         }
	      }
	
	   }
	
	   protected int func_225563_a_(int p_225563_1_, int p_225563_2_, int p_225563_3_, int p_225563_4_) {
	      int i = 0;
	      if (p_225563_4_ < p_225563_2_ && p_225563_4_ >= p_225563_2_ - 3) {
	         i = p_225563_3_;
	      } else if (p_225563_4_ == p_225563_2_) {
	         i = p_225563_3_;
	      }
	
	      return i;
	   }
		
	}

 

Last seen on 05:58, 24. Jan 2021
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
paste the customMushroom…
Sun, 08/30/2020 - 21:13

paste the customMushroom Feature where the custom tree feature goes