This commit is contained in:
Aleksey 2020-11-19 23:20:50 +03:00
commit 73a0cb890c
15 changed files with 131 additions and 82 deletions

View file

@ -13,6 +13,7 @@ import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import ru.betterend.blocks.basis.BlockPlant; import ru.betterend.blocks.basis.BlockPlant;
import ru.betterend.registry.EndBlocks;
public class BlockMurkweed extends BlockPlant { public class BlockMurkweed extends BlockPlant {
@Override @Override
@ -31,4 +32,9 @@ public class BlockMurkweed extends BlockPlant {
((LivingEntity) entity).addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 50)); ((LivingEntity) entity).addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 50));
} }
} }
@Override
protected boolean isTerrain(BlockState state) {
return state.isOf(EndBlocks.SHADOW_GRASS);
}
} }

View file

@ -18,6 +18,7 @@ import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import ru.betterend.blocks.basis.BlockPlant; import ru.betterend.blocks.basis.BlockPlant;
import ru.betterend.registry.EndBlocks;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class BlockNeedlegrass extends BlockPlant { public class BlockNeedlegrass extends BlockPlant {
@ -38,4 +39,9 @@ public class BlockNeedlegrass extends BlockPlant {
return Lists.newArrayList(new ItemStack(Items.STICK, MHelper.randRange(0, 2, MHelper.RANDOM))); return Lists.newArrayList(new ItemStack(Items.STICK, MHelper.randRange(0, 2, MHelper.RANDOM)));
} }
} }
@Override
protected boolean isTerrain(BlockState state) {
return state.isOf(EndBlocks.SHADOW_GRASS);
}
} }

View file

@ -17,6 +17,7 @@ import net.minecraft.world.BlockView;
import net.minecraft.world.StructureWorldAccess; import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import ru.betterend.blocks.basis.BlockPlantWithAge; import ru.betterend.blocks.basis.BlockPlantWithAge;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
@ -55,4 +56,9 @@ public class BlockShadowBerry extends BlockPlantWithAge {
public AbstractBlock.OffsetType getOffsetType() { public AbstractBlock.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return AbstractBlock.OffsetType.NONE;
} }
@Override
protected boolean isTerrain(BlockState state) {
return state.isOf(EndBlocks.SHADOW_GRASS);
}
} }

View file

@ -4,7 +4,6 @@ import java.io.Reader;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
public class BlockBark extends BlockPillar { public class BlockBark extends BlockPillar {

View file

@ -15,7 +15,6 @@ import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters; import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
public class BlockBookshelf extends BlockBase { public class BlockBookshelf extends BlockBase {

View file

@ -23,7 +23,6 @@ import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.interfaces.IdentifiedContext; import ru.betterend.interfaces.IdentifiedContext;
import ru.betterend.patterns.Patterned; import ru.betterend.patterns.Patterned;

View file

@ -112,6 +112,9 @@ public class EndBiomes {
} }
}); });
LAND_BIOMES.rebuild();
VOID_BIOMES.rebuild();
LAND_BIOMES.getBiomes().forEach((endBiome) -> { LAND_BIOMES.getBiomes().forEach((endBiome) -> {
Biome biome = biomeRegistry.get(endBiome.getID()); Biome biome = biomeRegistry.get(endBiome.getID());
endBiome.setActualBiome(biome); endBiome.setActualBiome(biome);

View file

@ -156,9 +156,25 @@ public class BlocksHelper {
if (state.getBlock() instanceof BlockGlowingFur) { if (state.getBlock() instanceof BlockGlowingFur) {
doubleCheck.add(POS.toImmutable()); doubleCheck.add(POS.toImmutable());
} }
// Liquids
if (!state.canPlaceAt(world, POS)) { else if (!state.getFluidState().isEmpty()) {
POS.setY(y - 1);
if (world.isAir(POS)) {
POS.setY(y);
while (!world.getFluidState(POS).isEmpty()) {
setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() + 1);
}
continue;
}
for (Direction dir : HORIZONTAL) {
if (world.isAir(POS.offset(dir))) {
world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0);
break;
}
}
}
else if (!state.canPlaceAt(world, POS)) {
// Chorus // Chorus
if (state.isOf(Blocks.CHORUS_PLANT)) { if (state.isOf(Blocks.CHORUS_PLANT)) {
Set<BlockPos> ends = Sets.newHashSet(); Set<BlockPos> ends = Sets.newHashSet();
@ -193,28 +209,6 @@ public class BlocksHelper {
POS.setY(POS.getY() - 1); POS.setY(POS.getY() - 1);
} }
} }
// Liquids
else if (!state.getFluidState().isEmpty()) {
POS.setY(y - 1);
if (world.isAir(POS)) {
POS.setY(y);
while (!world.getFluidState(POS).isEmpty()) {
setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() + 1);
}
continue;
}
BlockState st;
for (Direction dir : HORIZONTAL) {
if ((st = world.getBlockState(POS.offset(dir))).getMaterial().isReplaceable() && st.getFluidState().isEmpty()) {
world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0);
break;
}
}
if ((st = world.getBlockState(POS.up())).getMaterial().isReplaceable() && st.getFluidState().isEmpty()) {
world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0);
}
}
// Falling blocks // Falling blocks
else if (state.getBlock() instanceof FallingBlock) { else if (state.getBlock() instanceof FallingBlock) {
BlockState falling = state; BlockState falling = state;
@ -233,19 +227,15 @@ public class BlocksHelper {
} }
else { else {
POS.setY(y); POS.setY(y);
boolean place = true; BlockState replacement = AIR;
for (Direction dir : HORIZONTAL) { for (Direction dir : HORIZONTAL) {
state = world.getBlockState(POS.offset(dir)); state = world.getBlockState(POS.offset(dir));
if (!state.getFluidState().isEmpty()) { if (!state.getFluidState().isEmpty()) {
BlocksHelper.setWithoutUpdate(world, POS, state); replacement = state;
place = false;
break; break;
} }
} }
if (place) { BlocksHelper.setWithoutUpdate(world, POS, replacement);
BlocksHelper.setWithoutUpdate(world, POS, AIR);
}
POS.setY(y - ray); POS.setY(y - ray);
BlocksHelper.setWithoutUpdate(world, POS, falling); BlocksHelper.setWithoutUpdate(world, POS, falling);
} }
@ -256,14 +246,6 @@ public class BlocksHelper {
if (state.getBlock() instanceof BlockBlueVine) { if (state.getBlock() instanceof BlockBlueVine) {
while (state.isOf(EndBlocks.BLUE_VINE) || state.isOf(EndBlocks.BLUE_VINE_LANTERN) || state.isOf(EndBlocks.BLUE_VINE_FUR)) { while (state.isOf(EndBlocks.BLUE_VINE) || state.isOf(EndBlocks.BLUE_VINE_LANTERN) || state.isOf(EndBlocks.BLUE_VINE_FUR)) {
BlocksHelper.setWithoutUpdate(world, POS, AIR); BlocksHelper.setWithoutUpdate(world, POS, AIR);
for (Direction dir : HORIZONTAL) {
BlockPos p = POS.offset(dir);
state = world.getBlockState(p);
if (state.getBlock() instanceof BlockGlowingFur) {
BlocksHelper.setWithoutUpdate(world, p, AIR);
}
world.getBlockTickScheduler().schedule(p, world.getBlockState(p).getBlock(), 0);
}
POS.setY(POS.getY() + 1); POS.setY(POS.getY() + 1);
state = world.getBlockState(POS); state = world.getBlockState(POS);
} }
@ -276,7 +258,7 @@ public class BlocksHelper {
} }
// Other blocks // Other blocks
else { else {
BlocksHelper.setWithoutUpdate(world, POS, AIR); BlocksHelper.setWithoutUpdate(world, POS, getAirOrFluid(state));
} }
} }
} }
@ -291,6 +273,10 @@ public class BlocksHelper {
}); });
} }
private static BlockState getAirOrFluid(BlockState state) {
return state.getFluidState().isEmpty() ? AIR : state.getFluidState().getBlockState();
}
public static boolean isEndNylium(Block block) { public static boolean isEndNylium(Block block) {
return block.isIn(BlockTags.NYLIUM) && block.isIn(EndTags.END_GROUND); return block.isIn(BlockTags.NYLIUM) && block.isIn(EndTags.END_GROUND);
} }

View file

@ -3,10 +3,9 @@ package ru.betterend.world.biome;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import ru.betterend.config.Config; import ru.betterend.config.Config;
import ru.betterend.config.ConfigWriter;
import ru.betterend.config.ConfigKeeper.Entry; import ru.betterend.config.ConfigKeeper.Entry;
import ru.betterend.config.ConfigWriter;
public class BiomeConfig extends Config { public class BiomeConfig extends Config {

View file

@ -10,8 +10,6 @@ import com.google.gson.JsonObject;
import net.minecraft.structure.Structure; import net.minecraft.structure.Structure;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import ru.betterend.util.JsonFactory; import ru.betterend.util.JsonFactory;
import ru.betterend.util.StructureHelper; import ru.betterend.util.StructureHelper;
@ -53,9 +51,6 @@ public class EndBiome {
readStructureList(); readStructureList();
} }
public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) {
}
public EndBiome getEdge() { public EndBiome getEdge() {
return edge == null ? this : edge; return edge == null ? this : edge;
} }
@ -166,4 +161,8 @@ public class EndBiome {
public Biome getActualBiome() { public Biome getActualBiome() {
return this.actualBiome; return this.actualBiome;
} }
public float getGenChance() {
return this.genChance;
}
} }

View file

@ -19,7 +19,7 @@ public class UnderwaterPlantFeature extends UnderwaterPlantScatter {
@Override @Override
public boolean canGenerate(StructureWorldAccess world, Random random, BlockPos center, BlockPos blockPos, float radius) { public boolean canGenerate(StructureWorldAccess world, Random random, BlockPos center, BlockPos blockPos, float radius) {
return plant.canPlaceAt(plant.getDefaultState(), world, blockPos); return super.canSpawn(world, blockPos) && plant.canPlaceAt(plant.getDefaultState(), world, blockPos);
} }
@Override @Override

View file

@ -29,7 +29,7 @@ public abstract class UnderwaterPlantScatter extends ScatterFeature {
@Override @Override
protected boolean canSpawn(StructureWorldAccess world, BlockPos pos) { protected boolean canSpawn(StructureWorldAccess world, BlockPos pos) {
return !world.getFluidState(pos).isEmpty(); return world.getBlockState(pos).isOf(Blocks.WATER);
} }
@Override @Override

View file

@ -159,26 +159,19 @@ public class EndLakeFeature extends DefaultFeature {
state = world.getBlockState(POS.up()); state = world.getBlockState(POS.up());
state = canReplace(state) ? (y < waterLevel ? WATER : AIR) : state; state = canReplace(state) ? (y < waterLevel ? WATER : AIR) : state;
BlocksHelper.setWithoutUpdate(world, POS, state); BlocksHelper.setWithoutUpdate(world, POS, state);
/*if (y == waterLevel - 1 && !state.getFluidState().isEmpty()) {
world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0);
}*/
} }
pos = POS.down(); pos = POS.down();
if (world.getBlockState(pos).getBlock().isIn(EndTags.GEN_TERRAIN)) { if (world.getBlockState(pos).getBlock().isIn(EndTags.GEN_TERRAIN)) {
BlocksHelper.setWithoutUpdate(world, POS.down(), EndBlocks.ENDSTONE_DUST.getDefaultState()); BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.ENDSTONE_DUST.getDefaultState());
} }
pos = POS.up(); pos = POS.up();
while (canReplace(state = world.getBlockState(pos)) && !state.isAir() && state.getFluidState().isEmpty()) { while (canReplace(state = world.getBlockState(pos)) && !state.isAir() && state.getFluidState().isEmpty()) {
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR); BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
/*if (y == waterLevel - 1) {
world.getFluidTickScheduler().schedule(POS, WATER.getFluidState().getFluid(), 0);
}*/
pos = pos.up(); pos = pos.up();
} }
} }
// Make border // Make border
else if (y < waterLevel && y2 + x2 + z2 <= rb) { else if (y < waterLevel && y2 + x2 + z2 <= rb) {
//if (world.getBlockState(POS).getMaterial().isReplaceable()) {
if (world.isAir(POS.up())) { if (world.isAir(POS.up())) {
state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial(); state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial();
BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state : EndBlocks.ENDSTONE_DUST.getDefaultState()); BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state : EndBlocks.ENDSTONE_DUST.getDefaultState());
@ -200,21 +193,6 @@ public class EndLakeFeature extends DefaultFeature {
return true; return true;
} }
/*private void generateFoggyMushroomland(WorldAccess world, int x, int z, int waterLevel) {
if (NOISE.eval(x * 0.1, z * 0.1, 0) > 0) {
BlocksHelper.setWithoutUpdate(world, POS, BlockRegistry.BUBBLE_CORAL.getDefaultState());
}
else if (NOISE.eval(x * 0.1, z * 0.1, 1) > 0) {
BlocksHelper.setWithoutUpdate(world, POS, BlockRegistry.END_LILY.getDefaultState().with(BlockEndLily.SHAPE, TripleShape.BOTTOM));
BlockPos up = POS.up();
while (up.getY() < waterLevel) {
BlocksHelper.setWithoutUpdate(world, up, BlockRegistry.END_LILY.getDefaultState().with(BlockEndLily.SHAPE, TripleShape.MIDDLE));
up = up.up();
}
BlocksHelper.setWithoutUpdate(world, up, BlockRegistry.END_LILY.getDefaultState().with(BlockEndLily.SHAPE, TripleShape.TOP));
}
}*/
private boolean canReplace(BlockState state) { private boolean canReplace(BlockState state) {
return state.getMaterial().isReplaceable() return state.getMaterial().isReplaceable()
|| state.isIn(EndTags.GEN_TERRAIN) || state.isIn(EndTags.GEN_TERRAIN)

View file

@ -8,7 +8,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import ru.betterend.registry.EndBiomes;
import ru.betterend.world.biome.EndBiome; import ru.betterend.world.biome.EndBiome;
public class BiomePicker { public class BiomePicker {
@ -17,6 +16,7 @@ public class BiomePicker {
private float maxChanceUnmutable = 0; private float maxChanceUnmutable = 0;
private float maxChance = 0; private float maxChance = 0;
private int biomeCount = 0; private int biomeCount = 0;
private WeighTree tree;
public void addBiome(EndBiome biome) { public void addBiome(EndBiome biome) {
maxChance = biome.mutateGenChance(maxChance); maxChance = biome.mutateGenChance(maxChance);
@ -38,11 +38,7 @@ public class BiomePicker {
} }
public EndBiome getBiome(Random random) { public EndBiome getBiome(Random random) {
float chance = random.nextFloat() * maxChance; return tree.getBiome(random.nextFloat() * maxChance);
for (EndBiome biome: biomes)
if (biome.canGenerate(chance))
return biome;
return EndBiomes.END;
} }
public List<EndBiome> getBiomes() { public List<EndBiome> getBiomes() {
@ -52,4 +48,8 @@ public class BiomePicker {
public boolean containsImmutable(Identifier id) { public boolean containsImmutable(Identifier id) {
return immutableIDs.contains(id); return immutableIDs.contains(id);
} }
public void rebuild() {
tree = new WeighTree(biomes);
}
} }

View file

@ -0,0 +1,69 @@
package ru.betterend.world.generator;
import java.util.List;
import ru.betterend.world.biome.EndBiome;
public class WeighTree {
private final Node root;
public WeighTree(List<EndBiome> biomes) {
root = getNode(biomes);
}
public EndBiome getBiome(float value) {
return root.getBiome(value);
}
private Node getNode(List<EndBiome> biomes) {
int size = biomes.size();
if (size == 1) {
return new Leaf(biomes.get(0));
}
else if (size == 2) {
EndBiome first = biomes.get(0);
return new Branch(first.getGenChance(), new Leaf(first), new Leaf(biomes.get(1)));
}
else {
int index = size >> 1;
float separator = biomes.get(index).getGenChance();
Node a = getNode(biomes.subList(0, index + 1));
Node b = getNode(biomes.subList(index, size));
return new Branch(separator, a, b);
}
}
private abstract class Node {
abstract EndBiome getBiome(float value);
}
private class Branch extends Node {
final float separator;
final Node min;
final Node max;
public Branch(float separator, Node min, Node max) {
this.separator = separator;
this.min = min;
this.max = max;
}
@Override
EndBiome getBiome(float value) {
return value < separator ? min.getBiome(value) : max.getBiome(value);
}
}
private class Leaf extends Node {
final EndBiome biome;
Leaf(EndBiome biome) {
this.biome = biome;
}
@Override
EndBiome getBiome(float value) {
return biome;
}
}
}