Fixed structure features and code style
This commit is contained in:
parent
d431f2555c
commit
5a9365e2bb
153 changed files with 2304 additions and 2459 deletions
|
@ -1,10 +1,6 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.impl.biome.InternalBiomeData;
|
||||
|
@ -20,6 +16,9 @@ import net.minecraft.world.level.biome.Biomes;
|
|||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
public class BiomeAPI {
|
||||
/**
|
||||
* Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs.
|
||||
|
@ -33,6 +32,7 @@ public class BiomeAPI {
|
|||
|
||||
/**
|
||||
* Initialize registry for current server.
|
||||
*
|
||||
* @param server - {@link MinecraftServer}
|
||||
*/
|
||||
public static void initRegistry(MinecraftServer server) {
|
||||
|
@ -49,23 +49,19 @@ public class BiomeAPI {
|
|||
|
||||
/**
|
||||
* Adds {@link BCLBiome} to FabricAPI biomes as the Nether biome (with random {@link ClimateParameters}).
|
||||
*
|
||||
* @param biome - {@link BCLBiome}.
|
||||
*/
|
||||
public static void addNetherBiomeToFabricApi(BCLBiome biome) {
|
||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
|
||||
Random random = new Random(biome.getID().toString().hashCode());
|
||||
ClimateParameters parameters = new ClimateParameters(
|
||||
MHelper.randRange(-2F, 2F, random),
|
||||
MHelper.randRange(-2F, 2F, random),
|
||||
MHelper.randRange(-2F, 2F, random),
|
||||
MHelper.randRange(-2F, 2F, random),
|
||||
MHelper.randRange(-2F, 2F, random)
|
||||
);
|
||||
ClimateParameters parameters = new ClimateParameters(MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random));
|
||||
InternalBiomeData.addNetherBiome(key, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds {@link BCLBiome} to FabricAPI biomes as an End land biome (generating on islands).
|
||||
*
|
||||
* @param biome - {@link BCLBiome}.
|
||||
*/
|
||||
public static void addEndLandBiomeToFabricApi(BCLBiome biome) {
|
||||
|
@ -77,6 +73,7 @@ public class BiomeAPI {
|
|||
|
||||
/**
|
||||
* Adds {@link BCLBiome} to FabricAPI biomes as an End void biome (generating between islands in the void).
|
||||
*
|
||||
* @param biome - {@link BCLBiome}.
|
||||
*/
|
||||
public static void addEndVoidBiomeToFabricApi(BCLBiome biome) {
|
||||
|
@ -87,6 +84,7 @@ public class BiomeAPI {
|
|||
|
||||
/**
|
||||
* Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes.
|
||||
*
|
||||
* @param biome - {@link Biome} from world.
|
||||
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
|
||||
*/
|
||||
|
@ -99,6 +97,7 @@ public class BiomeAPI {
|
|||
|
||||
/**
|
||||
* Get {@link BCLBiome} from biome on client. Used in fog rendering.
|
||||
*
|
||||
* @param biome - {@link Biome} from client world.
|
||||
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
|
||||
*/
|
||||
|
@ -116,6 +115,7 @@ public class BiomeAPI {
|
|||
|
||||
/**
|
||||
* Get biome {@link ResourceLocation} from given {@link Biome}.
|
||||
*
|
||||
* @param biome - {@link Biome} from server world.
|
||||
* @return biome {@link ResourceLocation}.
|
||||
*/
|
||||
|
@ -123,9 +123,10 @@ public class BiomeAPI {
|
|||
ResourceLocation id = biomeRegistry.getKey(biome);
|
||||
return id == null ? EMPTY_BIOME.getID() : id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get {@link BCLBiome} from given {@link ResourceLocation}.
|
||||
*
|
||||
* @param biomeID - biome {@link ResourceLocation}.
|
||||
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
|
||||
*/
|
||||
|
@ -135,6 +136,7 @@ public class BiomeAPI {
|
|||
|
||||
/**
|
||||
* Get actual {@link Biome} from given {@link BCLBiome}. If it is null it will request it from current {@link Registry}.
|
||||
*
|
||||
* @param biome - {@link BCLBiome}.
|
||||
* @return {@link Biome}.
|
||||
*/
|
||||
|
@ -149,6 +151,7 @@ public class BiomeAPI {
|
|||
|
||||
/**
|
||||
* Check if biome with {@link ResourceLocation} exists in API registry.
|
||||
*
|
||||
* @param biomeID - biome {@link ResourceLocation}.
|
||||
* @return {@code true} if biome exists in API registry and {@code false} if not.
|
||||
*/
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import ru.bclib.util.WeightedList;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import ru.bclib.util.WeightedList;
|
||||
|
||||
public class BonemealAPI {
|
||||
private static final Map<ResourceLocation, Map<Block, WeightedList<Block>>> WATER_GRASS_BIOMES = Maps.newHashMap();
|
||||
private static final Map<ResourceLocation, Map<Block, WeightedList<Block>>> LAND_GRASS_BIOMES = Maps.newHashMap();
|
||||
|
@ -27,13 +26,13 @@ public class BonemealAPI {
|
|||
}
|
||||
|
||||
public static void addLandGrass(Block plant, Block... terrain) {
|
||||
for (Block block: terrain) {
|
||||
for (Block block : terrain) {
|
||||
addLandGrass(block, plant, 1F);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addLandGrass(ResourceLocation biome, Block plant, Block... terrain) {
|
||||
for (Block block: terrain) {
|
||||
for (Block block : terrain) {
|
||||
addLandGrass(biome, block, plant, 1F);
|
||||
}
|
||||
}
|
||||
|
@ -62,13 +61,13 @@ public class BonemealAPI {
|
|||
}
|
||||
|
||||
public static void addWaterGrass(Block plant, Block... terrain) {
|
||||
for (Block block: terrain) {
|
||||
for (Block block : terrain) {
|
||||
addWaterGrass(block, plant, 1F);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addWaterGrass(ResourceLocation biome, Block plant, Block... terrain) {
|
||||
for (Block block: terrain) {
|
||||
for (Block block : terrain) {
|
||||
addWaterGrass(biome, block, plant, 1F);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.chunk.storage.RegionFile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -8,17 +18,6 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.chunk.storage.RegionFile;
|
||||
|
||||
public class DataFixerAPI {
|
||||
private static final Map<String, String> REPLACEMENT = Maps.newHashMap();
|
||||
private static final Map<String, Integer> FIX_VERSIONS = Maps.newHashMap();
|
||||
|
@ -31,7 +30,7 @@ public class DataFixerAPI {
|
|||
|
||||
boolean shoudFix = false;
|
||||
Collection<ModContainer> mods = FabricLoader.getInstance().getAllMods();
|
||||
for (ModContainer mod: mods) {
|
||||
for (ModContainer mod : mods) {
|
||||
String name = mod.getMetadata().getId();
|
||||
int preVersion = WorldDataAPI.getIntModVersion(name);
|
||||
int version = getModVersion(mod.getMetadata().getVersion().toString());
|
||||
|
@ -39,7 +38,8 @@ public class DataFixerAPI {
|
|||
int fixVersion = FIX_VERSIONS.getOrDefault(name, version);
|
||||
shoudFix |= fixVersion < version && fixVersion >= preVersion;
|
||||
}
|
||||
};
|
||||
}
|
||||
;
|
||||
if (!shoudFix) {
|
||||
return;
|
||||
}
|
||||
|
@ -90,14 +90,15 @@ public class DataFixerAPI {
|
|||
|
||||
/**
|
||||
* Register block data fix. Fix will be applied on world load if current mod version will be newer than specified one.
|
||||
* @param modID - {@link String} mod id;
|
||||
*
|
||||
* @param modID - {@link String} mod id;
|
||||
* @param modVersion - {@link String} mod version, should be in format: %d.%d.%d
|
||||
* @param result - {@link String} new block name;
|
||||
* @param names - array of {@link String}, old block names to convert.
|
||||
* @param result - {@link String} new block name;
|
||||
* @param names - array of {@link String}, old block names to convert.
|
||||
*/
|
||||
protected static void addFix(String modID, String modVersion, String result, String... names) {
|
||||
FIX_VERSIONS.put(modID, getModVersion(modVersion));
|
||||
for (String name: names) {
|
||||
for (String name : names) {
|
||||
REPLACEMENT.put(name, result);
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +107,7 @@ public class DataFixerAPI {
|
|||
if (list == null) {
|
||||
list = Lists.newArrayList();
|
||||
}
|
||||
for (File file: dir.listFiles()) {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
getAllRegions(file, list);
|
||||
}
|
||||
|
@ -119,6 +120,7 @@ public class DataFixerAPI {
|
|||
|
||||
/**
|
||||
* Get mod version from string. String should be in format: %d.%d.%d
|
||||
*
|
||||
* @param version - {@link String} mod version.
|
||||
* @return int mod version.
|
||||
*/
|
||||
|
@ -137,6 +139,7 @@ public class DataFixerAPI {
|
|||
|
||||
/**
|
||||
* Get mod version from integer. String will be in format %d.%d.%d
|
||||
*
|
||||
* @param version - mod version in integer form.
|
||||
* @return {@link String} mod version.
|
||||
*/
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import ru.bclib.integration.ModIntegration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ModIntegrationAPI {
|
||||
private static final List<ModIntegration> INTEGRATIONS = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* Registers mod integration
|
||||
*
|
||||
* @param integration
|
||||
* @return
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ public class ModIntegrationAPI {
|
|||
|
||||
/**
|
||||
* Get all registered mod integrations.
|
||||
*
|
||||
* @return {@link List} of {@link ModIntegration}.
|
||||
*/
|
||||
public static List<ModIntegration> getIntegrations() {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.fabricmc.fabric.api.tag.TagRegistry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
|
@ -16,6 +14,8 @@ import net.minecraft.world.level.block.Blocks;
|
|||
import ru.bclib.BCLib;
|
||||
import ru.bclib.util.TagHelper;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class TagAPI {
|
||||
// Block Tags
|
||||
public static final Tag.Named<Block> BOOKSHELVES = makeCommonBlockTag("bookshelves");
|
||||
|
@ -34,22 +34,24 @@ public class TagAPI {
|
|||
public static final Tag.Named<Item> IRON_INGOTS = makeCommonItemTag("iron_ingots");
|
||||
public static final Tag.Named<Item> FURNACES = makeCommonItemTag("furnaces");
|
||||
public final static Tag.Named<Item> HAMMERS = makeItemTag("fabric", "hammers");
|
||||
|
||||
|
||||
/**
|
||||
* Get or create {@link Tag.Named}.
|
||||
*
|
||||
* @param containerSupplier - {@link TagCollection} {@link Supplier} tag collection;
|
||||
* @param id - {@link ResourceLocation} tag id.
|
||||
* @param id - {@link ResourceLocation} tag id.
|
||||
* @return {@link Tag.Named}.
|
||||
*/
|
||||
public static <T> Tag.Named<T> makeTag(Supplier<TagCollection<T>> containerSupplier, ResourceLocation id) {
|
||||
Tag<T> tag = containerSupplier.get().getTag(id);
|
||||
return tag == null ? TagRegistry.create(id, containerSupplier) : (Named<T>) tag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get or create {@link Block} {@link Tag.Named} with mod namespace.
|
||||
*
|
||||
* @param modID - {@link String} mod namespace (mod id);
|
||||
* @param name - {@link String} tag name.
|
||||
* @param name - {@link String} tag name.
|
||||
* @return {@link Block} {@link Tag.Named}.
|
||||
*/
|
||||
public static Tag.Named<Block> makeBlockTag(String modID, String name) {
|
||||
|
@ -58,8 +60,9 @@ public class TagAPI {
|
|||
|
||||
/**
|
||||
* Get or create {@link Item} {@link Tag.Named} with mod namespace.
|
||||
*
|
||||
* @param modID - {@link String} mod namespace (mod id);
|
||||
* @param name - {@link String} tag name.
|
||||
* @param name - {@link String} tag name.
|
||||
* @return {@link Item} {@link Tag.Named}.
|
||||
*/
|
||||
public static Tag.Named<Item> makeItemTag(String modID, String name) {
|
||||
|
@ -68,9 +71,10 @@ public class TagAPI {
|
|||
|
||||
/**
|
||||
* Get or create {@link Block} {@link Tag.Named}.
|
||||
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a>
|
||||
*
|
||||
* @param name - {@link String} tag name.
|
||||
* @return {@link Block} {@link Tag.Named}.
|
||||
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a>
|
||||
*/
|
||||
public static Tag.Named<Block> makeCommonBlockTag(String name) {
|
||||
return makeTag(BlockTags::getAllTags, new ResourceLocation("c", name));
|
||||
|
@ -78,9 +82,10 @@ public class TagAPI {
|
|||
|
||||
/**
|
||||
* Get or create {@link Item} {@link Tag.Named}.
|
||||
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a>
|
||||
*
|
||||
* @param name - {@link String} tag name.
|
||||
* @return {@link Item} {@link Tag.Named}.
|
||||
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a>
|
||||
*/
|
||||
public static Tag.Named<Item> makeCommonItemTag(String name) {
|
||||
return makeTag(ItemTags::getAllTags, new ResourceLocation("c", name));
|
||||
|
@ -88,6 +93,7 @@ public class TagAPI {
|
|||
|
||||
/**
|
||||
* Get or create Minecraft {@link Block} {@link Tag.Named}.
|
||||
*
|
||||
* @param name - {@link String} tag name.
|
||||
* @return {@link Block} {@link Tag.Named}.
|
||||
*/
|
||||
|
@ -99,6 +105,7 @@ public class TagAPI {
|
|||
|
||||
/**
|
||||
* Adds {@link Block} to NETHER_GROUND and GEN_TERRAIN tags to process it properly in terrain generators and block logic.
|
||||
*
|
||||
* @param block - {@link Block}.
|
||||
*/
|
||||
public static void addNetherGround(Block block) {
|
||||
|
@ -108,6 +115,7 @@ public class TagAPI {
|
|||
|
||||
/**
|
||||
* Adds {@link Block} to END_GROUND and GEN_TERRAIN tags to process it properly in terrain generators and block logic.
|
||||
*
|
||||
* @param block - {@link Block}.
|
||||
*/
|
||||
public static void addEndGround(Block block) {
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import ru.bclib.BCLib;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import ru.bclib.BCLib;
|
||||
|
||||
public class WorldDataAPI {
|
||||
private static final Map<String, CompoundTag> TAGS = Maps.newHashMap();
|
||||
private static final List<String> MODS = Lists.newArrayList();
|
||||
|
@ -52,6 +51,7 @@ public class WorldDataAPI {
|
|||
|
||||
/**
|
||||
* Register mod cache, world cache is located in world data folder.
|
||||
*
|
||||
* @param modID - {@link String} modID.
|
||||
*/
|
||||
public static void registerModCache(String modID) {
|
||||
|
@ -60,6 +60,7 @@ public class WorldDataAPI {
|
|||
|
||||
/**
|
||||
* Get root {@link CompoundTag} for mod cache in world data folder.
|
||||
*
|
||||
* @param modID - {@link String} modID.
|
||||
* @return {@link CompoundTag}
|
||||
*/
|
||||
|
@ -74,13 +75,14 @@ public class WorldDataAPI {
|
|||
|
||||
/**
|
||||
* Get {@link CompoundTag} with specified path from mod cache in world data folder.
|
||||
*
|
||||
* @param modID - {@link String} path to tag, dot-separated.
|
||||
* @return {@link CompoundTag}
|
||||
*/
|
||||
public static CompoundTag getCompoundTag(String modID, String path) {
|
||||
String[] parts = path.split("\\.");
|
||||
CompoundTag tag = getRootTag(modID);
|
||||
for (String part: parts) {
|
||||
for (String part : parts) {
|
||||
if (tag.contains(part)) {
|
||||
tag = tag.getCompound(part);
|
||||
}
|
||||
|
@ -95,6 +97,7 @@ public class WorldDataAPI {
|
|||
|
||||
/**
|
||||
* Forces mod cache file to be saved.
|
||||
*
|
||||
* @param modID {@link String} mod ID.
|
||||
*/
|
||||
public static void saveFile(String modID) {
|
||||
|
@ -108,6 +111,7 @@ public class WorldDataAPI {
|
|||
|
||||
/**
|
||||
* Get stored mod version (only for mods with registered cache).
|
||||
*
|
||||
* @return {@link String} mod version.
|
||||
*/
|
||||
public static String getModVersion(String modID) {
|
||||
|
@ -116,6 +120,7 @@ public class WorldDataAPI {
|
|||
|
||||
/**
|
||||
* Get stored mod version as integer (only for mods with registered cache).
|
||||
*
|
||||
* @return {@code int} mod version.
|
||||
*/
|
||||
public static int getIntModVersion(String modID) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue