Merge branch 'master' of https://github.com/paulevsGitch/BetterEnd
This commit is contained in:
commit
73a0cb890c
15 changed files with 131 additions and 82 deletions
|
@ -13,6 +13,7 @@ import net.minecraft.particle.ParticleTypes;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.blocks.basis.BlockPlant;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
||||
public class BlockMurkweed extends BlockPlant {
|
||||
@Override
|
||||
|
@ -31,4 +32,9 @@ public class BlockMurkweed extends BlockPlant {
|
|||
((LivingEntity) entity).addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 50));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTerrain(BlockState state) {
|
||||
return state.isOf(EndBlocks.SHADOW_GRASS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.loot.context.LootContextParameters;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.blocks.basis.BlockPlant;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTerrain(BlockState state) {
|
||||
return state.isOf(EndBlocks.SHADOW_GRASS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.world.BlockView;
|
|||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.blocks.basis.BlockPlantWithAge;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndItems;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
|
@ -55,4 +56,9 @@ public class BlockShadowBerry extends BlockPlantWithAge {
|
|||
public AbstractBlock.OffsetType getOffsetType() {
|
||||
return AbstractBlock.OffsetType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTerrain(BlockState state) {
|
||||
return state.isOf(EndBlocks.SHADOW_GRASS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.io.Reader;
|
|||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import ru.betterend.patterns.Patterns;
|
||||
|
||||
public class BlockBark extends BlockPillar {
|
||||
|
|
|
@ -15,7 +15,6 @@ import net.minecraft.loot.context.LootContext;
|
|||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import ru.betterend.patterns.Patterns;
|
||||
|
||||
public class BlockBookshelf extends BlockBase {
|
||||
|
|
|
@ -23,7 +23,6 @@ import net.minecraft.resource.Resource;
|
|||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.interfaces.IdentifiedContext;
|
||||
import ru.betterend.patterns.Patterned;
|
||||
|
|
|
@ -112,6 +112,9 @@ public class EndBiomes {
|
|||
}
|
||||
});
|
||||
|
||||
LAND_BIOMES.rebuild();
|
||||
VOID_BIOMES.rebuild();
|
||||
|
||||
LAND_BIOMES.getBiomes().forEach((endBiome) -> {
|
||||
Biome biome = biomeRegistry.get(endBiome.getID());
|
||||
endBiome.setActualBiome(biome);
|
||||
|
|
|
@ -156,9 +156,25 @@ public class BlocksHelper {
|
|||
if (state.getBlock() instanceof BlockGlowingFur) {
|
||||
doubleCheck.add(POS.toImmutable());
|
||||
}
|
||||
|
||||
if (!state.canPlaceAt(world, POS)) {
|
||||
|
||||
// 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;
|
||||
}
|
||||
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
|
||||
if (state.isOf(Blocks.CHORUS_PLANT)) {
|
||||
Set<BlockPos> ends = Sets.newHashSet();
|
||||
|
@ -193,28 +209,6 @@ public class BlocksHelper {
|
|||
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
|
||||
else if (state.getBlock() instanceof FallingBlock) {
|
||||
BlockState falling = state;
|
||||
|
@ -233,19 +227,15 @@ public class BlocksHelper {
|
|||
}
|
||||
else {
|
||||
POS.setY(y);
|
||||
boolean place = true;
|
||||
BlockState replacement = AIR;
|
||||
for (Direction dir : HORIZONTAL) {
|
||||
state = world.getBlockState(POS.offset(dir));
|
||||
if (!state.getFluidState().isEmpty()) {
|
||||
BlocksHelper.setWithoutUpdate(world, POS, state);
|
||||
place = false;
|
||||
replacement = state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (place) {
|
||||
BlocksHelper.setWithoutUpdate(world, POS, AIR);
|
||||
}
|
||||
|
||||
BlocksHelper.setWithoutUpdate(world, POS, replacement);
|
||||
POS.setY(y - ray);
|
||||
BlocksHelper.setWithoutUpdate(world, POS, falling);
|
||||
}
|
||||
|
@ -256,14 +246,6 @@ public class BlocksHelper {
|
|||
if (state.getBlock() instanceof BlockBlueVine) {
|
||||
while (state.isOf(EndBlocks.BLUE_VINE) || state.isOf(EndBlocks.BLUE_VINE_LANTERN) || state.isOf(EndBlocks.BLUE_VINE_FUR)) {
|
||||
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);
|
||||
state = world.getBlockState(POS);
|
||||
}
|
||||
|
@ -276,7 +258,7 @@ public class BlocksHelper {
|
|||
}
|
||||
// Other blocks
|
||||
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) {
|
||||
return block.isIn(BlockTags.NYLIUM) && block.isIn(EndTags.END_GROUND);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,9 @@ package ru.betterend.world.biome;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import ru.betterend.config.Config;
|
||||
import ru.betterend.config.ConfigWriter;
|
||||
import ru.betterend.config.ConfigKeeper.Entry;
|
||||
import ru.betterend.config.ConfigWriter;
|
||||
|
||||
public class BiomeConfig extends Config {
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import ru.betterend.util.JsonFactory;
|
||||
import ru.betterend.util.StructureHelper;
|
||||
|
@ -53,9 +51,6 @@ public class EndBiome {
|
|||
readStructureList();
|
||||
}
|
||||
|
||||
public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) {
|
||||
}
|
||||
|
||||
public EndBiome getEdge() {
|
||||
return edge == null ? this : edge;
|
||||
}
|
||||
|
@ -166,4 +161,8 @@ public class EndBiome {
|
|||
public Biome getActualBiome() {
|
||||
return this.actualBiome;
|
||||
}
|
||||
|
||||
public float getGenChance() {
|
||||
return this.genChance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class UnderwaterPlantFeature extends UnderwaterPlantScatter {
|
|||
|
||||
@Override
|
||||
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
|
||||
|
|
|
@ -29,7 +29,7 @@ public abstract class UnderwaterPlantScatter extends ScatterFeature {
|
|||
|
||||
@Override
|
||||
protected boolean canSpawn(StructureWorldAccess world, BlockPos pos) {
|
||||
return !world.getFluidState(pos).isEmpty();
|
||||
return world.getBlockState(pos).isOf(Blocks.WATER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -159,26 +159,19 @@ public class EndLakeFeature extends DefaultFeature {
|
|||
state = world.getBlockState(POS.up());
|
||||
state = canReplace(state) ? (y < waterLevel ? WATER : AIR) : state;
|
||||
BlocksHelper.setWithoutUpdate(world, POS, state);
|
||||
/*if (y == waterLevel - 1 && !state.getFluidState().isEmpty()) {
|
||||
world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0);
|
||||
}*/
|
||||
}
|
||||
pos = POS.down();
|
||||
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();
|
||||
while (canReplace(state = world.getBlockState(pos)) && !state.isAir() && state.getFluidState().isEmpty()) {
|
||||
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
|
||||
/*if (y == waterLevel - 1) {
|
||||
world.getFluidTickScheduler().schedule(POS, WATER.getFluidState().getFluid(), 0);
|
||||
}*/
|
||||
pos = pos.up();
|
||||
}
|
||||
}
|
||||
// Make border
|
||||
else if (y < waterLevel && y2 + x2 + z2 <= rb) {
|
||||
//if (world.getBlockState(POS).getMaterial().isReplaceable()) {
|
||||
if (world.isAir(POS.up())) {
|
||||
state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial();
|
||||
BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state : EndBlocks.ENDSTONE_DUST.getDefaultState());
|
||||
|
@ -200,21 +193,6 @@ public class EndLakeFeature extends DefaultFeature {
|
|||
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) {
|
||||
return state.getMaterial().isReplaceable()
|
||||
|| state.isIn(EndTags.GEN_TERRAIN)
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.google.common.collect.Lists;
|
|||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import ru.betterend.registry.EndBiomes;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
||||
public class BiomePicker {
|
||||
|
@ -17,6 +16,7 @@ public class BiomePicker {
|
|||
private float maxChanceUnmutable = 0;
|
||||
private float maxChance = 0;
|
||||
private int biomeCount = 0;
|
||||
private WeighTree tree;
|
||||
|
||||
public void addBiome(EndBiome biome) {
|
||||
maxChance = biome.mutateGenChance(maxChance);
|
||||
|
@ -38,11 +38,7 @@ public class BiomePicker {
|
|||
}
|
||||
|
||||
public EndBiome getBiome(Random random) {
|
||||
float chance = random.nextFloat() * maxChance;
|
||||
for (EndBiome biome: biomes)
|
||||
if (biome.canGenerate(chance))
|
||||
return biome;
|
||||
return EndBiomes.END;
|
||||
return tree.getBiome(random.nextFloat() * maxChance);
|
||||
}
|
||||
|
||||
public List<EndBiome> getBiomes() {
|
||||
|
@ -52,4 +48,8 @@ public class BiomePicker {
|
|||
public boolean containsImmutable(Identifier id) {
|
||||
return immutableIDs.contains(id);
|
||||
}
|
||||
|
||||
public void rebuild() {
|
||||
tree = new WeighTree(biomes);
|
||||
}
|
||||
}
|
||||
|
|
69
src/main/java/ru/betterend/world/generator/WeighTree.java
Normal file
69
src/main/java/ru/betterend/world/generator/WeighTree.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue