com.yungnickyoung.minecraft.yungsapi.world.structure.placement.EnhancedRandomSpread Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of YungsApi-1.21-Fabric Show documentation
Show all versions of YungsApi-1.21-Fabric Show documentation
A common API for YUNG's Minecraft mods
The newest version!
package com.yungnickyoung.minecraft.yungsapi.world.structure.placement;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.yungnickyoung.minecraft.yungsapi.module.StructurePlacementTypeModule;
import com.yungnickyoung.minecraft.yungsapi.world.structure.exclusion.EnhancedExclusionZone;
import java.util.Optional;
import net.minecraft.class_2382;
import net.minecraft.class_5699;
import net.minecraft.class_6872;
import net.minecraft.class_6873;
import net.minecraft.class_6875;
import net.minecraft.class_7869;
public class EnhancedRandomSpread extends class_6872 {
public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(builder -> builder
.group(
class_2382.method_39677(16).optionalFieldOf("locate_offset", class_2382.field_11176).forGetter(placement -> placement.method_41642()),
class_7154.field_37786.optionalFieldOf("frequency_reduction_method", class_7154.field_37782).forGetter(placement -> placement.method_41643()),
Codec.floatRange(0.0F, 1.0F).optionalFieldOf("frequency", 1.0F).forGetter(placement -> placement.method_41644()),
class_5699.field_33441.fieldOf("salt").forGetter(placement -> placement.method_41645()),
class_7152.field_37781.optionalFieldOf("exclusion_zone").forGetter(placement -> placement.method_41646()),
EnhancedExclusionZone.CODEC.optionalFieldOf("enhanced_exclusion_zone").forGetter(placement -> placement.enhancedExclusionZone),
class_5699.field_33441.fieldOf("spacing").forGetter(class_6872::method_41632),
class_5699.field_33441.fieldOf("separation").forGetter(class_6872::method_41633),
class_6873.field_36423.optionalFieldOf("spread_type", class_6873.field_36421).forGetter(class_6872::method_41634))
.apply(builder, builder.stable(EnhancedRandomSpread::new)))
.validate(EnhancedRandomSpread::validateSpacing);
private static DataResult validateSpacing(EnhancedRandomSpread placement) {
return placement.method_41632() <= placement.method_41633()
? DataResult.error(() -> "EnhancedRandomSpread's spacing has to be larger than separation")
: DataResult.success(placement);
}
private final Optional enhancedExclusionZone;
public EnhancedRandomSpread(class_2382 locateOffset,
class_7154 frequencyReductionMethod,
Float frequency,
Integer salt,
Optional exclusionZone,
Optional enhancedExclusionZone,
Integer spacing,
Integer separation,
class_6873 randomSpreadType) {
super(locateOffset, frequencyReductionMethod, frequency, salt, exclusionZone, spacing, separation, randomSpreadType);
this.enhancedExclusionZone = enhancedExclusionZone;
}
@Override
public class_6875> method_40166() {
return StructurePlacementTypeModule.ENHANCED_RANDOM_SPREAD;
}
@Override
public boolean method_41639(class_7869 chunkGeneratorStructureState, int x, int z) {
if (!super.method_41639(chunkGeneratorStructureState, x, z)) {
return false;
}
return this.enhancedExclusionZone.isEmpty()
|| !this.enhancedExclusionZone.get().isPlacementForbidden(chunkGeneratorStructureState, x, z);
}
}