Removed redundant code (moved to BCLib lists)

This commit is contained in:
paulevsGitch 2021-10-26 14:13:26 +03:00
parent 8a1490f00e
commit 9c1c1edb12
10 changed files with 18 additions and 115 deletions

View file

@ -1,10 +0,0 @@
package ru.betterend.interfaces;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import java.util.List;
public interface IBiomeList {
public List<ResourceKey<Biome>> getBiomes();
}

View file

@ -1,7 +0,0 @@
package ru.betterend.interfaces;
public interface ShuffelingListExtended<U> {
public boolean isEmpty();
public U getOne();
}

View file

@ -1,27 +0,0 @@
package ru.betterend.mixin.common;
import net.minecraft.world.entity.ai.behavior.ShufflingList;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import ru.betterend.interfaces.ShuffelingListExtended;
import java.util.List;
@Mixin(ShufflingList.class)
public abstract class ShuffelingListMixin<U> implements ShuffelingListExtended<U> {
@Shadow
@Final
protected List<ShufflingList.WeightedEntry<U>> entries;
public boolean isEmpty() {
return this.entries.isEmpty();
}
@Shadow
public abstract ShufflingList<U> shuffle();
public U getOne() {
return this.shuffle().stream().findFirst().orElseThrow(RuntimeException::new);
}
}

View file

@ -1,38 +0,0 @@
package ru.betterend.mixin.common;
import com.google.common.collect.Lists;
import net.fabricmc.fabric.impl.biome.InternalBiomeData;
import net.fabricmc.fabric.impl.biome.WeightedBiomePicker;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.betterend.interfaces.IBiomeList;
import java.util.List;
@Mixin(value = WeightedBiomePicker.class, remap = false)
public class WeightedBiomePickerMixin implements IBiomeList {
private final List<ResourceKey<Biome>> biomes = Lists.newArrayList();
@Inject(method = "addBiome", at = @At("TAIL"))
private void be_addBiome(final ResourceKey<Biome> biome, final double weight, CallbackInfo info) {
if (be_isCorrectPicker(WeightedBiomePicker.class.cast(this))) {
biomes.add(biome);
}
}
@Override
public List<ResourceKey<Biome>> getBiomes() {
return biomes;
}
private boolean be_isCorrectPicker(WeightedBiomePicker picker) {
return picker == InternalBiomeData.getEndBiomesMap()
.get(Biomes.SMALL_END_ISLANDS) || picker == InternalBiomeData.getEndBarrensMap()
.get(Biomes.END_BARRENS);
}
}

View file

@ -6,17 +6,19 @@ import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.Feature;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.BiomeAPI;
import ru.bclib.util.WeightedList;
import ru.bclib.world.biomes.BCLBiomeDef; import ru.bclib.world.biomes.BCLBiomeDef;
import ru.bclib.world.features.BCLFeature; import ru.bclib.world.features.BCLFeature;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.interfaces.ShuffelingListExtended;
import ru.betterend.registry.EndSounds; import ru.betterend.registry.EndSounds;
import ru.betterend.world.biome.EndBiome; import ru.betterend.world.biome.EndBiome;
import ru.betterend.world.features.terrain.caves.CaveChunkPopulatorFeature; import ru.betterend.world.features.terrain.caves.CaveChunkPopulatorFeature;
import java.util.Random;
public class EndCaveBiome extends EndBiome { public class EndCaveBiome extends EndBiome {
final private ShufflingList<Feature<?>> floorFeatures = new ShufflingList<>(); private WeightedList<Feature<?>> floorFeatures = new WeightedList<Feature<?>>();
final private ShufflingList<Feature<?>> ceilFeatures = new ShufflingList<>(); private WeightedList<Feature<?>> ceilFeatures = new WeightedList<Feature<?>>();
public EndCaveBiome(BCLBiomeDef definition) { public EndCaveBiome(BCLBiomeDef definition) {
super(makeDef(definition)); super(makeDef(definition));
@ -24,8 +26,7 @@ public class EndCaveBiome extends EndBiome {
private static BCLBiomeDef makeDef(BCLBiomeDef definition) { private static BCLBiomeDef makeDef(BCLBiomeDef definition) {
BCLFeature feature = BCLFeature.makeChunkFeature( BCLFeature feature = BCLFeature.makeChunkFeature(
BetterEnd.makeID(definition.getID() BetterEnd.makeID(definition.getID().getPath() + "_cave_populator"),
.getPath() + "_cave_populator"),
new CaveChunkPopulatorFeature(() -> (EndCaveBiome) BiomeAPI.getBiome(definition.getID())) new CaveChunkPopulatorFeature(() -> (EndCaveBiome) BiomeAPI.getBiome(definition.getID()))
); );
definition.setCategory(BiomeCategory.NONE).addFeature(feature); definition.setCategory(BiomeCategory.NONE).addFeature(feature);
@ -34,22 +35,20 @@ public class EndCaveBiome extends EndBiome {
return definition; return definition;
} }
public void addFloorFeature(Feature<?> feature, int weight) { public void addFloorFeature(Feature<?> feature, float weight) {
floorFeatures.add(feature, weight); floorFeatures.add(feature, weight);
} }
public void addCeilFeature(Feature<?> feature, int weight) { public void addCeilFeature(Feature<?> feature, float weight) {
ceilFeatures.add(feature, weight); ceilFeatures.add(feature, weight);
} }
public Feature<?> getFloorFeature() { public Feature<?> getFloorFeature(Random random) {
return ((ShuffelingListExtended<Feature<?>>) floorFeatures).isEmpty() ? null : ((ShuffelingListExtended<Feature<?>>) floorFeatures) return floorFeatures.isEmpty() ? null : floorFeatures.get(random);
.getOne();
} }
public Feature<?> getCeilFeature() { public Feature<?> getCeilFeature(Random random) {
return ((ShuffelingListExtended<Feature<?>>) ceilFeatures).isEmpty() ? null : ((ShuffelingListExtended<Feature<?>>) ceilFeatures) return ceilFeatures.isEmpty() ? null : ceilFeatures.get(random);
.getOne();
} }
public float getFloorDensity() { public float getFloorDensity() {

View file

@ -109,7 +109,7 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
floorPositions.forEach((pos) -> { floorPositions.forEach((pos) -> {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock); BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
if (density > 0 && random.nextFloat() <= density) { if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getFloorFeature(); Feature<?> feature = biome.getFloorFeature(random);
if (feature != null) { if (feature != null) {
feature.place(new FeaturePlaceContext<>(world, null, random, pos.above(), null)); feature.place(new FeaturePlaceContext<>(world, null, random, pos.above(), null));
} }
@ -125,7 +125,7 @@ public class CaveChunkPopulatorFeature extends DefaultFeature {
BlocksHelper.setWithoutUpdate(world, pos, ceilBlock); BlocksHelper.setWithoutUpdate(world, pos, ceilBlock);
} }
if (density > 0 && random.nextFloat() <= density) { if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(); Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) { if (feature != null) {
feature.place(new FeaturePlaceContext<>(world, null, random, pos.below(), null)); feature.place(new FeaturePlaceContext<>(world, null, random, pos.below(), null));
} }

View file

@ -97,7 +97,7 @@ public abstract class EndCaveFeature extends DefaultFeature {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock); BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
} }
if (density > 0 && random.nextFloat() <= density) { if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getFloorFeature(); Feature<?> feature = biome.getFloorFeature(random);
if (feature != null) { if (feature != null) {
feature.place(new FeaturePlaceContext<>(world, null, random, pos.above(), null)); feature.place(new FeaturePlaceContext<>(world, null, random, pos.above(), null));
} }
@ -113,7 +113,7 @@ public abstract class EndCaveFeature extends DefaultFeature {
BlocksHelper.setWithoutUpdate(world, pos, ceilBlock); BlocksHelper.setWithoutUpdate(world, pos, ceilBlock);
} }
if (density > 0 && random.nextFloat() <= density) { if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(); Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) { if (feature != null) {
feature.place(new FeaturePlaceContext<>(world, null, random, pos.below(), null)); feature.place(new FeaturePlaceContext<>(world, null, random, pos.below(), null));
} }

View file

@ -195,7 +195,7 @@ public class TunelCaveFeature extends EndCaveFeature {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock); BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
} }
if (density > 0 && random.nextFloat() <= density) { if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getFloorFeature(); Feature<?> feature = biome.getFloorFeature(random);
if (feature != null) { if (feature != null) {
feature.place(new FeaturePlaceContext<>(world, null, random, pos.above(), null)); feature.place(new FeaturePlaceContext<>(world, null, random, pos.above(), null));
} }
@ -212,7 +212,7 @@ public class TunelCaveFeature extends EndCaveFeature {
BlocksHelper.setWithoutUpdate(world, pos, ceilBlock); BlocksHelper.setWithoutUpdate(world, pos, ceilBlock);
} }
if (density > 0 && random.nextFloat() <= density) { if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(); Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) { if (feature != null) {
feature.place(new FeaturePlaceContext<>(world, null, random, pos.below(), null)); feature.place(new FeaturePlaceContext<>(world, null, random, pos.below(), null));
} }

View file

@ -5,8 +5,6 @@ import net.minecraft.util.Mth;
import ru.betterend.config.Configs; import ru.betterend.config.Configs;
public class GeneratorOptions { public class GeneratorOptions {
private static int biomeSizeLand;
private static int biomeSizeVoid;
private static int biomeSizeCaves; private static int biomeSizeCaves;
private static boolean hasPortal; private static boolean hasPortal;
private static boolean hasPillars; private static boolean hasPillars;
@ -31,8 +29,6 @@ public class GeneratorOptions {
private static boolean directSpikeHeight; private static boolean directSpikeHeight;
public static void init() { public static void init() {
biomeSizeLand = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeLand", 256);
biomeSizeVoid = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeVoid", 256);
biomeSizeCaves = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeCaves", 32); biomeSizeCaves = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeCaves", 32);
hasPortal = Configs.GENERATOR_CONFIG.getBoolean("portal", "hasPortal", true); hasPortal = Configs.GENERATOR_CONFIG.getBoolean("portal", "hasPortal", true);
hasPillars = Configs.GENERATOR_CONFIG.getBoolean("spikes", "hasSpikes", true); hasPillars = Configs.GENERATOR_CONFIG.getBoolean("spikes", "hasSpikes", true);
@ -88,14 +84,6 @@ public class GeneratorOptions {
islandDistChunk = (circleRadius >> 3); // Twice bigger than normal islandDistChunk = (circleRadius >> 3); // Twice bigger than normal
} }
public static int getBiomeSizeLand() {
return Mth.clamp(biomeSizeLand, 1, 8192);
}
public static int getBiomeSizeVoid() {
return Mth.clamp(biomeSizeVoid, 1, 8192);
}
public static int getBiomeSizeCaves() { public static int getBiomeSizeCaves() {
return Mth.clamp(biomeSizeCaves, 1, 8192); return Mth.clamp(biomeSizeCaves, 1, 8192);
} }

View file

@ -7,7 +7,6 @@
"BiomeGenerationSettingsAccessor", "BiomeGenerationSettingsAccessor",
"NoiseBasedChunkGeneratorMixin", "NoiseBasedChunkGeneratorMixin",
"ChunkBiomeContainerMixin", "ChunkBiomeContainerMixin",
"WeightedBiomePickerMixin",
"ChorusPlantFeatureMixin", "ChorusPlantFeatureMixin",
"PlayerAdvancementsMixin", "PlayerAdvancementsMixin",
"ChorusFlowerBlockMixin", "ChorusFlowerBlockMixin",
@ -17,7 +16,6 @@
"PotionBrewingAccessor", "PotionBrewingAccessor",
"MinecraftServerMixin", "MinecraftServerMixin",
"EndDragonFightMixin", "EndDragonFightMixin",
"ShuffelingListMixin",
"WorldGenRegionMixin", "WorldGenRegionMixin",
"BlockBehaviourMixin", "BlockBehaviourMixin",
"DimensionTypeMixin", "DimensionTypeMixin",