Skip to content

Commit

Permalink
Fixed crash
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoMett committed Jan 20, 2024
1 parent 1b6cd10 commit 692604e
Showing 1 changed file with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.level.levelgen.feature.configurations.SimpleBlockConfiguration;
import org.jline.utils.Log;

import java.util.ArrayList;
import java.util.Random;

public class RandomFungusFeatureConfiguration extends Feature<SimpleBlockConfiguration>
Expand All @@ -24,38 +25,40 @@ public RandomFungusFeatureConfiguration()
@Override
public boolean place(FeaturePlaceContext<SimpleBlockConfiguration> placeContext)
{
BlockPos origin = placeContext.origin();
String biomeName = placeContext.level().registryAccess().registryOrThrow(Registries.BIOME).getKey(placeContext.level().getBiome(origin).get()).toString();
float biomeTemp = placeContext.level().getBiome(origin).get().getModifiedClimateSettings().temperature();
float biomeDownfall = placeContext.level().getBiome(origin).get().getModifiedClimateSettings().downfall();
Log.info(biomeName, ": ", biomeTemp, ", ", biomeDownfall);

//get random species
Random random = new Random();
FungusSpeciesHandler.FungusSpecies randomSpecies = FungusSpeciesHandler.INSTANCE.getSpeciesList()
.get(random.nextInt(FungusSpeciesHandler.INSTANCE.getSpeciesList().size()));
ArrayList<FungusSpeciesHandler.FungusSpecies> speciesList = FungusSpeciesHandler.INSTANCE.getSpeciesList();
if(!speciesList.isEmpty())
{
BlockPos origin = placeContext.origin();
String biomeName = placeContext.level().registryAccess().registryOrThrow(Registries.BIOME).getKey(placeContext.level().getBiome(origin).get()).toString();
float biomeTemp = placeContext.level().getBiome(origin).get().getModifiedClimateSettings().temperature();
float biomeDownfall = placeContext.level().getBiome(origin).get().getModifiedClimateSettings().downfall();
Log.info(biomeName, ": ", biomeTemp, ", ", biomeDownfall);

//spawn fungus with the correct type
if(randomSpecies.fungusType.equals("colored_crimson_fungus")) //FIXME I don't like this plain string, it's better to use a const
placeContext.level().setBlock(origin, ModBlocks.COLORED_CRIMSON_FUNGUS.get().defaultBlockState(), 0); //WTF is the third parameter??
else
placeContext.level().setBlock(origin, ModBlocks.COLORED_WARPED_FUNGUS.get().defaultBlockState(), 0);
//get random species
Random random = new Random();
FungusSpeciesHandler.FungusSpecies randomSpecies = speciesList
.get(random.nextInt(FungusSpeciesHandler.INSTANCE.getSpeciesList().size()));

//edit its block entity
BlockEntity blockEntity = placeContext.level().getBlockEntity(origin);
if(blockEntity instanceof ColoredFungusBlockEntity)
{
ColoredFungusBlockEntity coloredFungusBlockEntity = (ColoredFungusBlockEntity) blockEntity;
//spawn fungus with the correct type
if (randomSpecies.fungusType.equals("colored_crimson_fungus")) //FIXME I don't like this plain string, it's better to use a const
placeContext.level().setBlock(origin, ModBlocks.COLORED_CRIMSON_FUNGUS.get().defaultBlockState(), 0); //WTF is the third parameter??
else
placeContext.level().setBlock(origin, ModBlocks.COLORED_WARPED_FUNGUS.get().defaultBlockState(), 0);

//FIXME these two line below are no good. I want to call one method only
coloredFungusBlockEntity.getFungusData().setColors(randomSpecies.colors);
coloredFungusBlockEntity.getFungusData().loadFrom(randomSpecies.defaultTraits, randomSpecies.defaultTraits);
//edit its block entity
BlockEntity blockEntity = placeContext.level().getBlockEntity(origin);
if (blockEntity instanceof ColoredFungusBlockEntity coloredFungusBlockEntity)
{
//FIXME these two line below are no good. I want to call one method only
coloredFungusBlockEntity.getFungusData().setColors(randomSpecies.colors);
coloredFungusBlockEntity.getFungusData().loadFrom(randomSpecies.defaultTraits, randomSpecies.defaultTraits);
} else {
Log.error("WHY THIS BLOCKENTITY ISN'T A COLORED FUNGUS?");
return false;
}
return true;
}
else
{
Log.error("WHY THIS BLOCKENTITY ISN'T A COLORED FUNGUS?");
return false;
}
return true;
}
}

0 comments on commit 692604e

Please sign in to comment.