Reorganized Imports/Packages
This commit is contained in:
parent
a8beba9196
commit
770a5b4046
854 changed files with 42775 additions and 41811 deletions
229
src/main/java/org/betterx/betterend/util/BlockFixer.java
Normal file
229
src/main/java/org/betterx/betterend/util/BlockFixer.java
Normal file
|
@ -0,0 +1,229 @@
|
|||
package org.betterx.betterend.util;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.FallingBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.betterx.bclib.blocks.BaseDoublePlantBlock;
|
||||
import org.betterx.bclib.blocks.BaseVineBlock;
|
||||
import org.betterx.bclib.blocks.StalactiteBlock;
|
||||
import org.betterx.bclib.util.BlocksHelper;
|
||||
import org.betterx.betterend.blocks.BlueVineBlock;
|
||||
import org.betterx.betterend.blocks.basis.FurBlock;
|
||||
import org.betterx.betterend.registry.EndBlocks;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BlockFixer {
|
||||
private static final BlockState AIR = Blocks.AIR.defaultBlockState();
|
||||
private static final BlockState WATER = Blocks.WATER.defaultBlockState();
|
||||
|
||||
public static void fixBlocks(LevelAccessor level, BlockPos start, BlockPos end) {
|
||||
final Registry<DimensionType> registry = level.registryAccess()
|
||||
.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
final ResourceLocation dimKey = registry.getKey(level.dimensionType());
|
||||
if (dimKey != null && "world_blender".equals(dimKey.getNamespace())) {
|
||||
return;
|
||||
}
|
||||
final Set<BlockPos> doubleCheck = Sets.newConcurrentHashSet();
|
||||
final int dx = end.getX() - start.getX() + 1;
|
||||
final int dz = end.getZ() - start.getZ() + 1;
|
||||
final int count = dx * dz;
|
||||
final int minY = Math.max(start.getY(), level.getMinBuildHeight());
|
||||
final int maxY = Math.min(end.getY(), level.getMaxBuildHeight());
|
||||
IntStream.range(0, count).parallel().forEach(index -> {
|
||||
MutableBlockPos POS = new MutableBlockPos();
|
||||
POS.setX((index % dx) + start.getX());
|
||||
POS.setZ((index / dx) + start.getZ());
|
||||
BlockState state;
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
POS.setY(y);
|
||||
state = level.getBlockState(POS);
|
||||
|
||||
if (state.getBlock() instanceof FurBlock) {
|
||||
doubleCheck.add(POS.immutable());
|
||||
}
|
||||
// Liquids
|
||||
else if (!state.getFluidState().isEmpty()) {
|
||||
if (!state.canSurvive(level, POS)) {
|
||||
setWithoutUpdate(level, POS, WATER);
|
||||
POS.setY(POS.getY() - 1);
|
||||
state = level.getBlockState(POS);
|
||||
while (!state.canSurvive(level, POS)) {
|
||||
state = state.getFluidState().isEmpty() ? AIR : WATER;
|
||||
setWithoutUpdate(level, POS, state);
|
||||
POS.setY(POS.getY() - 1);
|
||||
state = level.getBlockState(POS);
|
||||
}
|
||||
}
|
||||
POS.setY(y - 1);
|
||||
if (level.isEmptyBlock(POS)) {
|
||||
POS.setY(y);
|
||||
while (!level.getFluidState(POS).isEmpty()) {
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
POS.setY(POS.getY() + 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (Direction dir : BlocksHelper.HORIZONTAL) {
|
||||
if (level.isEmptyBlock(POS.relative(dir))) {
|
||||
try {
|
||||
level.scheduleTick(POS, state.getFluidState().getType(), 0);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) {
|
||||
POS.setY(POS.getY() - 1);
|
||||
if (level.isEmptyBlock(POS)) {
|
||||
POS.setY(POS.getY() + 1);
|
||||
while (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) {
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
POS.setY(POS.getY() + 1);
|
||||
state = level.getBlockState(POS);
|
||||
}
|
||||
}
|
||||
} else if (state.getBlock() instanceof StalactiteBlock) {
|
||||
if (!state.canSurvive(level, POS)) {
|
||||
if (level.getBlockState(POS.above()).getBlock() instanceof StalactiteBlock) {
|
||||
while (state.getBlock() instanceof StalactiteBlock) {
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
POS.setY(POS.getY() + 1);
|
||||
state = level.getBlockState(POS);
|
||||
}
|
||||
} else {
|
||||
while (state.getBlock() instanceof StalactiteBlock) {
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
POS.setY(POS.getY() - 1);
|
||||
state = level.getBlockState(POS);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (state.is(EndBlocks.CAVE_PUMPKIN)) {
|
||||
if (!level.getBlockState(POS.above()).is(EndBlocks.CAVE_PUMPKIN_SEED)) {
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
}
|
||||
} else if (!state.canSurvive(level, POS)) {
|
||||
// Chorus
|
||||
if (state.is(Blocks.CHORUS_PLANT)) {
|
||||
Set<BlockPos> ends = Sets.newHashSet();
|
||||
Set<BlockPos> add = Sets.newHashSet();
|
||||
ends.add(POS.immutable());
|
||||
|
||||
for (int i = 0; i < 64 && !ends.isEmpty(); i++) {
|
||||
ends.forEach((pos) -> {
|
||||
setWithoutUpdate(level, pos, AIR);
|
||||
for (Direction dir : BlocksHelper.HORIZONTAL) {
|
||||
BlockPos p = pos.relative(dir);
|
||||
BlockState st = level.getBlockState(p);
|
||||
if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER)) && !st.canSurvive(
|
||||
level,
|
||||
p
|
||||
)) {
|
||||
add.add(p);
|
||||
}
|
||||
}
|
||||
BlockPos p = pos.above();
|
||||
BlockState st = level.getBlockState(p);
|
||||
if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER)) && !st.canSurvive(
|
||||
level,
|
||||
p
|
||||
)) {
|
||||
add.add(p);
|
||||
}
|
||||
});
|
||||
ends.clear();
|
||||
ends.addAll(add);
|
||||
add.clear();
|
||||
}
|
||||
}
|
||||
// Vines
|
||||
else if (state.getBlock() instanceof BaseVineBlock) {
|
||||
while (level.getBlockState(POS).getBlock() instanceof BaseVineBlock) {
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
POS.setY(POS.getY() - 1);
|
||||
}
|
||||
}
|
||||
// Falling blocks
|
||||
else if (state.getBlock() instanceof FallingBlock) {
|
||||
BlockState falling = state;
|
||||
|
||||
POS.setY(POS.getY() - 1);
|
||||
state = level.getBlockState(POS);
|
||||
|
||||
int ray = BlocksHelper.downRayRep(level, POS.immutable(), 64);
|
||||
if (ray > 32) {
|
||||
setWithoutUpdate(level, POS, Blocks.END_STONE.defaultBlockState());
|
||||
if (level.getRandom().nextBoolean()) {
|
||||
POS.setY(POS.getY() - 1);
|
||||
state = level.getBlockState(POS);
|
||||
setWithoutUpdate(level, POS, Blocks.END_STONE.defaultBlockState());
|
||||
}
|
||||
} else {
|
||||
POS.setY(y);
|
||||
BlockState replacement = AIR;
|
||||
for (Direction dir : BlocksHelper.HORIZONTAL) {
|
||||
state = level.getBlockState(POS.relative(dir));
|
||||
if (!state.getFluidState().isEmpty()) {
|
||||
replacement = state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
setWithoutUpdate(level, POS, replacement);
|
||||
POS.setY(y - ray);
|
||||
setWithoutUpdate(level, POS, falling);
|
||||
}
|
||||
}
|
||||
// Blocks without support
|
||||
else {
|
||||
// Blue Vine
|
||||
if (state.getBlock() instanceof BlueVineBlock) {
|
||||
while (state.is(EndBlocks.BLUE_VINE) || state.is(EndBlocks.BLUE_VINE_LANTERN) || state.is(
|
||||
EndBlocks.BLUE_VINE_FUR)) {
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
POS.setY(POS.getY() + 1);
|
||||
state = level.getBlockState(POS);
|
||||
}
|
||||
}
|
||||
// Double plants
|
||||
if (state.getBlock() instanceof BaseDoublePlantBlock) {
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
POS.setY(POS.getY() + 1);
|
||||
setWithoutUpdate(level, POS, AIR);
|
||||
}
|
||||
// Other blocks
|
||||
else {
|
||||
setWithoutUpdate(level, POS, getAirOrFluid(state));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
doubleCheck.forEach((pos) -> {
|
||||
if (!level.getBlockState(pos).canSurvive(level, pos)) {
|
||||
setWithoutUpdate(level, pos, AIR);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static BlockState getAirOrFluid(BlockState state) {
|
||||
return state.getFluidState().isEmpty() ? AIR : state.getFluidState().createLegacyBlock();
|
||||
}
|
||||
|
||||
private static void setWithoutUpdate(LevelAccessor world, BlockPos pos, BlockState state) {
|
||||
synchronized (world) {
|
||||
BlocksHelper.setWithoutUpdate(world, pos, state);
|
||||
}
|
||||
}
|
||||
}
|
122
src/main/java/org/betterx/betterend/util/BonemealPlants.java
Normal file
122
src/main/java/org/betterx/betterend/util/BonemealPlants.java
Normal file
|
@ -0,0 +1,122 @@
|
|||
package org.betterx.betterend.util;
|
||||
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.betterx.bclib.api.BonemealAPI;
|
||||
import org.betterx.betterend.blocks.basis.EndTerrainBlock;
|
||||
import org.betterx.betterend.registry.EndBiomes;
|
||||
import org.betterx.betterend.registry.EndBlocks;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BonemealPlants {
|
||||
public static void init() {
|
||||
BonemealAPI.addLandGrass(EndBlocks.CREEPING_MOSS, EndBlocks.END_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.UMBRELLA_MOSS, EndBlocks.END_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.CREEPING_MOSS, EndBlocks.END_MYCELIUM);
|
||||
BonemealAPI.addLandGrass(EndBlocks.UMBRELLA_MOSS, EndBlocks.END_MYCELIUM);
|
||||
|
||||
BonemealAPI.addLandGrass(EndBlocks.CAVE_GRASS, EndBlocks.CAVE_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.CHORUS_GRASS, EndBlocks.CHORUS_NYLIUM);
|
||||
BonemealAPI.addLandGrass(EndBlocks.CRYSTAL_GRASS, EndBlocks.CRYSTAL_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.SHADOW_PLANT, EndBlocks.SHADOW_GRASS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.BUSHY_GRASS, EndBlocks.PINK_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.AMBER_GRASS, EndBlocks.AMBER_MOSS);
|
||||
|
||||
BonemealAPI.addLandGrass(EndBlocks.JUNGLE_GRASS, EndBlocks.JUNGLE_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.TWISTED_UMBRELLA_MOSS, EndBlocks.JUNGLE_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.SMALL_JELLYSHROOM, EndBlocks.JUNGLE_MOSS, 0.1F);
|
||||
|
||||
BonemealAPI.addLandGrass(
|
||||
EndBiomes.GLOWING_GRASSLANDS.getID(),
|
||||
EndBlocks.BLOOMING_COOKSONIA,
|
||||
EndBlocks.END_MOSS
|
||||
);
|
||||
BonemealAPI.addLandGrass(EndBiomes.GLOWING_GRASSLANDS.getID(), EndBlocks.VAIOLUSH_FERN, EndBlocks.END_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBiomes.GLOWING_GRASSLANDS.getID(), EndBlocks.FRACTURN, EndBlocks.END_MOSS);
|
||||
BonemealAPI.addLandGrass(EndBiomes.GLOWING_GRASSLANDS.getID(), EndBlocks.SALTEAGO, EndBlocks.END_MOSS);
|
||||
|
||||
BonemealAPI.addLandGrass(
|
||||
EndBiomes.GLOWING_GRASSLANDS.getID(),
|
||||
EndBlocks.CREEPING_MOSS,
|
||||
EndBlocks.END_MOSS,
|
||||
0.1F
|
||||
);
|
||||
BonemealAPI.addLandGrass(
|
||||
EndBiomes.GLOWING_GRASSLANDS.getID(),
|
||||
EndBlocks.UMBRELLA_MOSS,
|
||||
EndBlocks.END_MOSS,
|
||||
0.1F
|
||||
);
|
||||
BonemealAPI.addLandGrass(
|
||||
EndBiomes.GLOWING_GRASSLANDS.getID(),
|
||||
EndBlocks.TWISTED_UMBRELLA_MOSS,
|
||||
EndBlocks.END_MOSS,
|
||||
0.1F
|
||||
);
|
||||
|
||||
BonemealAPI.addLandGrass(EndBlocks.ORANGO, EndBlocks.RUTISCUS);
|
||||
BonemealAPI.addLandGrass(EndBlocks.AERIDIUM, EndBlocks.RUTISCUS, 0.2F);
|
||||
BonemealAPI.addLandGrass(EndBlocks.LUTEBUS, EndBlocks.RUTISCUS, 0.2F);
|
||||
BonemealAPI.addLandGrass(EndBlocks.LAMELLARIUM, EndBlocks.RUTISCUS);
|
||||
|
||||
BonemealAPI.addLandGrass(EndBiomes.LANTERN_WOODS.getID(), EndBlocks.AERIDIUM, EndBlocks.RUTISCUS, 0.2F);
|
||||
BonemealAPI.addLandGrass(EndBiomes.LANTERN_WOODS.getID(), EndBlocks.LAMELLARIUM, EndBlocks.RUTISCUS);
|
||||
BonemealAPI.addLandGrass(EndBiomes.LANTERN_WOODS.getID(), EndBlocks.BOLUX_MUSHROOM, EndBlocks.RUTISCUS, 0.05F);
|
||||
|
||||
BonemealAPI.addLandGrass(
|
||||
EndBlocks.GLOBULAGUS,
|
||||
EndBlocks.SANGNUM,
|
||||
EndBlocks.MOSSY_OBSIDIAN,
|
||||
EndBlocks.MOSSY_DRAGON_BONE
|
||||
);
|
||||
BonemealAPI.addLandGrass(
|
||||
EndBlocks.CLAWFERN,
|
||||
EndBlocks.SANGNUM,
|
||||
EndBlocks.MOSSY_OBSIDIAN,
|
||||
EndBlocks.MOSSY_DRAGON_BONE
|
||||
);
|
||||
BonemealAPI.addLandGrass(EndBlocks.SANGNUM, EndBlocks.SMALL_AMARANITA_MUSHROOM, 0.1F);
|
||||
BonemealAPI.addLandGrass(EndBlocks.SMALL_AMARANITA_MUSHROOM, EndBlocks.MOSSY_OBSIDIAN, 0.1F);
|
||||
BonemealAPI.addLandGrass(EndBlocks.SMALL_AMARANITA_MUSHROOM, EndBlocks.MOSSY_DRAGON_BONE, 0.1F);
|
||||
|
||||
BonemealAPI.addLandGrass(EndBlocks.GLOBULAGUS, EndBlocks.MOSSY_DRAGON_BONE);
|
||||
BonemealAPI.addLandGrass(EndBlocks.CLAWFERN, EndBlocks.MOSSY_DRAGON_BONE);
|
||||
BonemealAPI.addLandGrass(EndBlocks.SMALL_AMARANITA_MUSHROOM, EndBlocks.MOSSY_DRAGON_BONE, 0.1F);
|
||||
|
||||
BonemealAPI.addLandGrass(EndBlocks.GLOBULAGUS, EndBlocks.MOSSY_OBSIDIAN);
|
||||
BonemealAPI.addLandGrass(EndBlocks.CLAWFERN, EndBlocks.MOSSY_OBSIDIAN);
|
||||
BonemealAPI.addLandGrass(EndBlocks.SMALL_AMARANITA_MUSHROOM, EndBlocks.MOSSY_OBSIDIAN, 0.1F);
|
||||
|
||||
Block[] charnias = new Block[]{
|
||||
EndBlocks.CHARNIA_CYAN,
|
||||
EndBlocks.CHARNIA_GREEN,
|
||||
EndBlocks.CHARNIA_ORANGE,
|
||||
EndBlocks.CHARNIA_LIGHT_BLUE,
|
||||
EndBlocks.CHARNIA_PURPLE,
|
||||
EndBlocks.CHARNIA_RED
|
||||
};
|
||||
List<Block> terrain = Lists.newArrayList();
|
||||
EndBlocks.getModBlocks().forEach(block -> {
|
||||
if (block instanceof EndTerrainBlock) {
|
||||
terrain.add(block);
|
||||
}
|
||||
});
|
||||
terrain.add(Blocks.END_STONE);
|
||||
terrain.add(EndBlocks.ENDSTONE_DUST);
|
||||
terrain.add(EndBlocks.CAVE_MOSS);
|
||||
terrain.add(EndBlocks.SULPHURIC_ROCK.stone);
|
||||
terrain.add(EndBlocks.VIOLECITE.stone);
|
||||
terrain.add(EndBlocks.FLAVOLITE.stone);
|
||||
terrain.add(EndBlocks.AZURE_JADESTONE.stone);
|
||||
terrain.add(EndBlocks.VIRID_JADESTONE.stone);
|
||||
terrain.add(EndBlocks.SANDY_JADESTONE.stone);
|
||||
terrain.add(EndBlocks.BRIMSTONE);
|
||||
Block[] terrainBlocks = terrain.toArray(new Block[terrain.size()]);
|
||||
for (Block charnia : charnias) {
|
||||
BonemealAPI.addWaterGrass(charnia, terrainBlocks);
|
||||
}
|
||||
}
|
||||
}
|
13
src/main/java/org/betterx/betterend/util/GlobalState.java
Normal file
13
src/main/java/org/betterx/betterend/util/GlobalState.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package org.betterx.betterend.util;
|
||||
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
|
||||
public class GlobalState {
|
||||
private static final ThreadLocal<GlobalState> STATE = ThreadLocal.withInitial(() -> new GlobalState());
|
||||
|
||||
public static GlobalState stateForThread() {
|
||||
return STATE.get();
|
||||
}
|
||||
|
||||
public final MutableBlockPos POS = new MutableBlockPos();
|
||||
}
|
40
src/main/java/org/betterx/betterend/util/LangUtil.java
Normal file
40
src/main/java/org/betterx/betterend/util/LangUtil.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package org.betterx.betterend.util;
|
||||
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
|
||||
|
||||
public class LangUtil {
|
||||
public final static String CONFIG_ELEMENT = "configuration";
|
||||
|
||||
private String element;
|
||||
|
||||
public LangUtil(String element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public void setElement(String key) {
|
||||
this.element = key;
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return getString(element, key);
|
||||
}
|
||||
|
||||
public MutableComponent getText(String key) {
|
||||
return getText(element, key);
|
||||
}
|
||||
|
||||
public static String translate(String key) {
|
||||
return I18n.get(key);
|
||||
}
|
||||
|
||||
public static String getString(String element, String key) {
|
||||
return translate(String.format("%s.%s", element, key));
|
||||
}
|
||||
|
||||
public static MutableComponent getText(String element, String key) {
|
||||
return Component.translatable(getString(element, key));
|
||||
}
|
||||
}
|
153
src/main/java/org/betterx/betterend/util/LootTableUtil.java
Normal file
153
src/main/java/org/betterx/betterend/util/LootTableUtil.java
Normal file
|
@ -0,0 +1,153 @@
|
|||
package org.betterx.betterend.util;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.storage.loot.entries.LootItem;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
|
||||
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
||||
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
|
||||
|
||||
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
|
||||
import net.fabricmc.fabric.api.loot.v1.FabricLootSupplierBuilder;
|
||||
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
|
||||
|
||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.complexmaterials.WoodenComplexMaterial;
|
||||
import org.betterx.bclib.world.biomes.BCLBiome;
|
||||
import org.betterx.betterend.BetterEnd;
|
||||
import org.betterx.betterend.registry.EndBiomes;
|
||||
import org.betterx.betterend.registry.EndBlocks;
|
||||
import org.betterx.betterend.registry.EndItems;
|
||||
|
||||
public class LootTableUtil {
|
||||
private static final ResourceLocation END_CITY_TREASURE_ID = new ResourceLocation("chests/end_city_treasure");
|
||||
private static final ResourceLocation COMMON = BetterEnd.makeID("chests/common");
|
||||
private static final ResourceLocation FOGGY_MUSHROOMLAND = BetterEnd.makeID("chests/foggy_mushroomland");
|
||||
private static final ResourceLocation CHORUS_FOREST = BetterEnd.makeID("chests/chorus_forest");
|
||||
private static final ResourceLocation SHADOW_FOREST = BetterEnd.makeID("chests/shadow_forest");
|
||||
private static final ResourceLocation LANTERN_WOODS = BetterEnd.makeID("chests/lantern_woods");
|
||||
private static final ResourceLocation UMBRELLA_JUNGLE = BetterEnd.makeID("chests/umbrella_jungle");
|
||||
|
||||
public static void init() {
|
||||
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, table, setter) -> {
|
||||
if (END_CITY_TREASURE_ID.equals(id)) {
|
||||
FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(ConstantValue.exactly(1));
|
||||
builder.withCondition(LootItemRandomChanceCondition.randomChance(0.2f).build());
|
||||
builder.withEntry(LootItem.lootTableItem(Items.GHAST_TEAR).build());
|
||||
table.withPool(builder);
|
||||
|
||||
builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(0, 3));
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_STRANGE_AND_ALIEN).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_GRASPING_AT_STARS).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_ENDSEEKER).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_EO_DRACONA).build());
|
||||
table.withPool(builder);
|
||||
} else if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
|
||||
addCommonItems(table);
|
||||
if (FOGGY_MUSHROOMLAND.equals(id)) {
|
||||
FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(4, 8));
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.MOSSY_GLOWSHROOM.getBlock(WoodenComplexMaterial.BLOCK_PLANKS))
|
||||
.build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.MOSSY_GLOWSHROOM_SAPLING).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.BLUE_VINE_SEED).build());
|
||||
table.withPool(builder);
|
||||
} else if (CHORUS_FOREST.equals(id)) {
|
||||
FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(4, 8));
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.PYTHADENDRON.getBlock(WoodenComplexMaterial.BLOCK_PLANKS))
|
||||
.build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.PYTHADENDRON_SAPLING).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.CHORUS_MUSHROOM).build());
|
||||
table.withPool(builder);
|
||||
} else if (SHADOW_FOREST.equals(id)) {
|
||||
FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(4, 8));
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.DRAGON_TREE.getBlock(WoodenComplexMaterial.BLOCK_PLANKS))
|
||||
.build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.DRAGON_TREE_SAPLING).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.SHADOW_BERRY).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.SHADOW_BERRY_RAW).build());
|
||||
table.withPool(builder);
|
||||
} else if (LANTERN_WOODS.equals(id)) {
|
||||
FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(4, 8));
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.LUCERNIA.getBlock(WoodenComplexMaterial.BLOCK_PLANKS))
|
||||
.build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.LUCERNIA_SAPLING).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.BOLUX_MUSHROOM).build());
|
||||
table.withPool(builder);
|
||||
} else if (UMBRELLA_JUNGLE.equals(id)) {
|
||||
FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(4, 8));
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.UMBRELLA_TREE.getBlock(WoodenComplexMaterial.BLOCK_PLANKS))
|
||||
.build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.UMBRELLA_TREE_SAPLING).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.SMALL_JELLYSHROOM).build());
|
||||
table.withPool(builder);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static ResourceLocation getTable(Holder<Biome> biome) {
|
||||
BCLBiome bclBiome = BiomeAPI.getBiome(biome.value());
|
||||
if (bclBiome == EndBiomes.FOGGY_MUSHROOMLAND) {
|
||||
return FOGGY_MUSHROOMLAND;
|
||||
} else if (bclBiome == EndBiomes.CHORUS_FOREST) {
|
||||
return CHORUS_FOREST;
|
||||
} else if (bclBiome == EndBiomes.SHADOW_FOREST) {
|
||||
return SHADOW_FOREST;
|
||||
} else if (bclBiome == EndBiomes.LANTERN_WOODS) {
|
||||
return LANTERN_WOODS;
|
||||
} else if (bclBiome == EndBiomes.UMBRELLA_JUNGLE) {
|
||||
return UMBRELLA_JUNGLE;
|
||||
}
|
||||
return COMMON;
|
||||
}
|
||||
|
||||
private static void addCommonItems(FabricLootSupplierBuilder table) {
|
||||
FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(0, 2));
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_STRANGE_AND_ALIEN).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_GRASPING_AT_STARS).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_ENDSEEKER).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_EO_DRACONA).build());
|
||||
table.withPool(builder);
|
||||
|
||||
builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(4, 8));
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.THALLASIUM.ingot).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.THALLASIUM.rawOre).build());
|
||||
builder.withEntry(LootItem.lootTableItem(Items.ENDER_PEARL).build());
|
||||
table.withPool(builder);
|
||||
|
||||
builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(2, 4));
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.TERMINITE.ingot).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.ENDER_SHARD).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.AURORA_CRYSTAL).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.THALLASIUM.axe).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.THALLASIUM.pickaxe).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.THALLASIUM.hoe).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.THALLASIUM.sword).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.THALLASIUM.shovel).build());
|
||||
builder.withEntry(LootItem.lootTableItem(Items.ENDER_EYE).build());
|
||||
builder.withEntry(LootItem.lootTableItem(Blocks.OBSIDIAN).build());
|
||||
table.withPool(builder);
|
||||
|
||||
builder = FabricLootPoolBuilder.builder();
|
||||
builder.setRolls(UniformGenerator.between(0, 4));
|
||||
builder.withEntry(LootItem.lootTableItem(EndBlocks.FLAVOLITE_RUNED).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.AETERNIUM_INGOT).build());
|
||||
builder.withEntry(LootItem.lootTableItem(EndItems.AMBER_GEM).build());
|
||||
builder.withEntry(LootItem.lootTableItem(Items.END_CRYSTAL).build());
|
||||
builder.withEntry(LootItem.lootTableItem(Items.GHAST_TEAR).build());
|
||||
table.withPool(builder);
|
||||
}
|
||||
}
|
277
src/main/java/org/betterx/betterend/util/StructureErode.java
Normal file
277
src/main/java/org/betterx/betterend/util/StructureErode.java
Normal file
|
@ -0,0 +1,277 @@
|
|||
package org.betterx.betterend.util;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.api.tag.CommonBlockTags;
|
||||
import org.betterx.bclib.util.BlocksHelper;
|
||||
import org.betterx.bclib.util.MHelper;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class StructureErode {
|
||||
private static final Direction[] DIR = BlocksHelper.makeHorizontal();
|
||||
|
||||
public static void erode(WorldGenLevel world, BoundingBox bounds, int iterations, RandomSource random) {
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
boolean canDestruct = true;
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
for (int x = bounds.minX(); x <= bounds.maxX(); x++) {
|
||||
mut.setX(x);
|
||||
for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) {
|
||||
mut.setZ(z);
|
||||
for (int y = bounds.maxY(); y >= bounds.minY(); y--) {
|
||||
mut.setY(y);
|
||||
BlockState state = world.getBlockState(mut);
|
||||
boolean ignore = ignore(state, world, mut);
|
||||
if (canDestruct && BlocksHelper.isInvulnerable(
|
||||
state,
|
||||
world,
|
||||
mut
|
||||
) && random.nextInt(8) == 0 && world.isEmptyBlock(
|
||||
mut.below(2))) {
|
||||
int r = MHelper.randRange(1, 4, random);
|
||||
int cx = mut.getX();
|
||||
int cy = mut.getY();
|
||||
int cz = mut.getZ();
|
||||
int x1 = cx - r;
|
||||
int y1 = cy - r;
|
||||
int z1 = cz - r;
|
||||
int x2 = cx + r;
|
||||
int y2 = cy + r;
|
||||
int z2 = cz + r;
|
||||
for (int px = x1; px <= x2; px++) {
|
||||
int dx = px - cx;
|
||||
dx *= dx;
|
||||
mut.setX(px);
|
||||
for (int py = y1; py <= y2; py++) {
|
||||
int dy = py - cy;
|
||||
dy *= dy;
|
||||
mut.setY(py);
|
||||
for (int pz = z1; pz <= z2; pz++) {
|
||||
int dz = pz - cz;
|
||||
dz *= dz;
|
||||
mut.setZ(pz);
|
||||
if (dx + dy + dz <= r && BlocksHelper.isInvulnerable(
|
||||
world.getBlockState(mut),
|
||||
world,
|
||||
mut
|
||||
)) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mut.setX(cx);
|
||||
mut.setY(cy);
|
||||
mut.setZ(cz);
|
||||
canDestruct = false;
|
||||
continue;
|
||||
} else if (ignore) {
|
||||
continue;
|
||||
}
|
||||
if (!state.isAir() && random.nextBoolean()) {
|
||||
MHelper.shuffle(DIR, random);
|
||||
for (Direction dir : DIR) {
|
||||
if (world.isEmptyBlock(mut.relative(dir)) && world.isEmptyBlock(mut.below()
|
||||
.relative(dir))) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
|
||||
mut.move(dir).move(Direction.DOWN);
|
||||
for (int py = mut.getY(); y >= bounds.minY() - 10; y--) {
|
||||
mut.setY(py - 1);
|
||||
if (!world.isEmptyBlock(mut)) {
|
||||
mut.setY(py);
|
||||
BlocksHelper.setWithoutUpdate(world, mut, state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else if (random.nextInt(8) == 0 && !BlocksHelper.isInvulnerable(
|
||||
world.getBlockState(mut.above()),
|
||||
world,
|
||||
mut
|
||||
)) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int x = bounds.minX(); x <= bounds.maxX(); x++) {
|
||||
mut.setX(x);
|
||||
for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) {
|
||||
mut.setZ(z);
|
||||
for (int y = bounds.maxY(); y >= bounds.minY(); y--) {
|
||||
mut.setY(y);
|
||||
BlockState state = world.getBlockState(mut);
|
||||
if (!ignore(state, world, mut) && world.isEmptyBlock(mut.below())) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
|
||||
for (int py = mut.getY(); py >= bounds.minY() - 10; py--) {
|
||||
mut.setY(py - 1);
|
||||
if (!world.isEmptyBlock(mut)) {
|
||||
mut.setY(py);
|
||||
BlocksHelper.setWithoutUpdate(world, mut, state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void erodeIntense(WorldGenLevel world, BoundingBox bounds, RandomSource random) {
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
MutableBlockPos mut2 = new MutableBlockPos();
|
||||
int minY = bounds.minY() - 10;
|
||||
for (int x = bounds.minX(); x <= bounds.maxX(); x++) {
|
||||
mut.setX(x);
|
||||
for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) {
|
||||
mut.setZ(z);
|
||||
for (int y = bounds.maxY(); y >= bounds.minY(); y--) {
|
||||
mut.setY(y);
|
||||
BlockState state = world.getBlockState(mut);
|
||||
if (!ignore(state, world, mut)) {
|
||||
if (random.nextInt(6) == 0) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
|
||||
if (random.nextBoolean()) {
|
||||
int px = MHelper.floor(random.nextGaussian() * 2 + x + 0.5);
|
||||
int pz = MHelper.floor(random.nextGaussian() * 2 + z + 0.5);
|
||||
mut2.set(px, y, pz);
|
||||
while (world.getBlockState(mut2).getMaterial().isReplaceable() && mut2.getY() > minY) {
|
||||
mut2.setY(mut2.getY() - 1);
|
||||
}
|
||||
if (!world.getBlockState(mut2).isAir() && state.canSurvive(world, mut2)) {
|
||||
mut2.setY(mut2.getY() + 1);
|
||||
BlocksHelper.setWithoutUpdate(world, mut2, state);
|
||||
}
|
||||
}
|
||||
} else if (random.nextInt(8) == 0) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drop(world, bounds);
|
||||
}
|
||||
|
||||
private static void drop(WorldGenLevel world, BoundingBox bounds) {
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
|
||||
Set<BlockPos> blocks = Sets.newHashSet();
|
||||
Set<BlockPos> edge = Sets.newHashSet();
|
||||
Set<BlockPos> add = Sets.newHashSet();
|
||||
|
||||
for (int x = bounds.minX(); x <= bounds.maxX(); x++) {
|
||||
mut.setX(x);
|
||||
for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) {
|
||||
mut.setZ(z);
|
||||
for (int y = bounds.minY(); y <= bounds.maxY(); y++) {
|
||||
mut.setY(y);
|
||||
BlockState state = world.getBlockState(mut);
|
||||
if (!ignore(state, world, mut) && isTerrainNear(world, mut)) {
|
||||
edge.add(mut.immutable());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (edge.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (!edge.isEmpty()) {
|
||||
for (BlockPos center : edge) {
|
||||
for (Direction dir : BlocksHelper.DIRECTIONS) {
|
||||
BlockState state = world.getBlockState(center);
|
||||
if (state.isCollisionShapeFullBlock(world, center)) {
|
||||
mut.set(center).move(dir);
|
||||
if (bounds.isInside(mut)) {
|
||||
state = world.getBlockState(mut);
|
||||
if (!ignore(state, world, mut) && !blocks.contains(mut)) {
|
||||
add.add(mut.immutable());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blocks.addAll(edge);
|
||||
edge.clear();
|
||||
edge.addAll(add);
|
||||
add.clear();
|
||||
}
|
||||
|
||||
int minY = bounds.minY() - 10;
|
||||
for (int x = bounds.minX(); x <= bounds.maxX(); x++) {
|
||||
mut.setX(x);
|
||||
for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) {
|
||||
mut.setZ(z);
|
||||
for (int y = bounds.minY(); y <= bounds.maxY(); y++) {
|
||||
mut.setY(y);
|
||||
BlockState state = world.getBlockState(mut);
|
||||
if (!ignore(state, world, mut) && !blocks.contains(mut)) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
|
||||
while (world.getBlockState(mut).getMaterial().isReplaceable() && mut.getY() > minY) {
|
||||
mut.setY(mut.getY() - 1);
|
||||
}
|
||||
if (mut.getY() > minY) {
|
||||
mut.setY(mut.getY() + 1);
|
||||
BlocksHelper.setWithoutUpdate(world, mut, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean ignore(BlockState state, WorldGenLevel world, BlockPos pos) {
|
||||
if (state.is(CommonBlockTags.GEN_END_STONES) || state.is(BlockTags.NYLIUM)) {
|
||||
return true;
|
||||
}
|
||||
return !state.getMaterial().equals(Material.STONE) || BlocksHelper.isInvulnerable(state, world, pos);
|
||||
}
|
||||
|
||||
private static boolean isTerrainNear(WorldGenLevel world, BlockPos pos) {
|
||||
for (Direction dir : BlocksHelper.DIRECTIONS) {
|
||||
if (world.getBlockState(pos.relative(dir)).is(CommonBlockTags.GEN_END_STONES)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void cover(WorldGenLevel world, BoundingBox bounds, RandomSource random, BlockState defaultBlock) {
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
for (int x = bounds.minX(); x <= bounds.maxX(); x++) {
|
||||
mut.setX(x);
|
||||
for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) {
|
||||
mut.setZ(z);
|
||||
BlockState top = BiomeAPI.findTopMaterial(world.getBiome(mut)).orElse(defaultBlock);
|
||||
for (int y = bounds.maxY(); y >= bounds.minY(); y--) {
|
||||
mut.setY(y);
|
||||
BlockState state = world.getBlockState(mut);
|
||||
if (state.is(CommonBlockTags.END_STONES) && !world.getBlockState(mut.above())
|
||||
.getMaterial()
|
||||
.isSolidBlocking()) {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, top);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue