Code style fix & version update
This commit is contained in:
parent
6266b30088
commit
179ada3296
20 changed files with 392 additions and 427 deletions
|
@ -8,7 +8,7 @@ yarn_mappings= 6
|
|||
loader_version= 0.11.6
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.2.4
|
||||
mod_version = 0.2.5
|
||||
maven_group = ru.bclib
|
||||
archives_base_name = bclib
|
||||
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.config.Configs;
|
||||
import ru.bclib.config.PathConfig;
|
||||
import ru.bclib.config.SessionConfig;
|
||||
import ru.bclib.util.Logger;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -12,278 +24,259 @@ import java.util.Set;
|
|||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
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 ru.bclib.BCLib;
|
||||
import ru.bclib.config.Configs;
|
||||
import ru.bclib.config.PathConfig;
|
||||
import ru.bclib.config.SessionConfig;
|
||||
import ru.bclib.util.Logger;
|
||||
|
||||
public class DataFixerAPI2 {
|
||||
private static final Logger LOGGER = new Logger("DataFixerAPI");
|
||||
|
||||
public static void fixData(SessionConfig config) {
|
||||
if (true || !Configs.MAIN_CONFIG.getBoolean(Configs.MAIN_PATCH_CATEGORY, "applyPatches", true)){
|
||||
LOGGER.info("World Patches are disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
final File dir = config.levelFolder;
|
||||
Patch.MigrationData data = Patch.createMigrationData(config);
|
||||
if (!data.hasAnyFixes()) {
|
||||
LOGGER.info("Everything up to date");
|
||||
return;
|
||||
}
|
||||
|
||||
List<File> regions = getAllRegions(dir, null);
|
||||
regions.parallelStream().forEach((file) -> {
|
||||
try {
|
||||
LOGGER.info("Inspecting " + file);
|
||||
boolean[] changed = new boolean[1];
|
||||
RegionFile region = new RegionFile(file, file.getParentFile(), true);
|
||||
for (int x = 0; x < 32; x++) {
|
||||
for (int z = 0; z < 32; z++) {
|
||||
ChunkPos pos = new ChunkPos(x, z);
|
||||
changed[0] = false;
|
||||
if (region.hasChunk(pos)) {
|
||||
DataInputStream input = region.getChunkDataInputStream(pos);
|
||||
CompoundTag root = NbtIo.read(input);
|
||||
// if ((root.toString().contains("betternether") || root.toString().contains("bclib")) && root.toString().contains("chest")) {
|
||||
// NbtIo.write(root, new File(file.toString() + "-" + x + "-" + z + ".nbt"));
|
||||
// }
|
||||
input.close();
|
||||
|
||||
ListTag tileEntities = root.getCompound("Level").getList("TileEntities", 10);
|
||||
fixItemArrayWithID(tileEntities, changed, data, true);
|
||||
|
||||
ListTag sections = root.getCompound("Level").getList("Sections", 10);
|
||||
sections.forEach((tag) -> {
|
||||
ListTag palette = ((CompoundTag) tag).getList("Palette", 10);
|
||||
palette.forEach((blockTag) -> {
|
||||
CompoundTag blockTagCompound = ((CompoundTag) blockTag);
|
||||
changed[0] = data.replaceStringFromIDs(blockTagCompound, "Name");
|
||||
});
|
||||
});
|
||||
if (changed[0]) {
|
||||
LOGGER.warning("Writing '{}': {}/{}", file, x, z);
|
||||
DataOutputStream output = region.getChunkDataOutputStream(pos);
|
||||
NbtIo.write(root, output);
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
data.markApplied();
|
||||
}
|
||||
|
||||
private static boolean fixItemArrayWithID(ListTag items, boolean[] changed, Patch.MigrationData data, boolean recursive){
|
||||
items.forEach(inTag -> {
|
||||
final CompoundTag tag = (CompoundTag) inTag;
|
||||
|
||||
changed[0] |= data.replaceStringFromIDs(tag, "id");
|
||||
|
||||
if (recursive && tag.contains("Items")){
|
||||
changed[0] |= fixItemArrayWithID(tag.getList("Items", 10), changed, data, true);
|
||||
}
|
||||
});
|
||||
|
||||
return changed[0];
|
||||
}
|
||||
|
||||
private static List<File> getAllRegions(File dir, List<File> list) {
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
for (File file : dir.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
getAllRegions(file, list);
|
||||
}
|
||||
else if (file.isFile() && file.getName().endsWith(".mca")) {
|
||||
list.add(file);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public abstract static class Patch {
|
||||
private static List<Patch> ALL = new ArrayList<>(10);
|
||||
private final int level;
|
||||
@NotNull
|
||||
private final String modID;
|
||||
|
||||
static List<Patch> getALL() {
|
||||
return ALL;
|
||||
}
|
||||
|
||||
/**
|
||||
* register a new Patch
|
||||
* @param patch A #Supplier that will instantiate the new Patch Object
|
||||
*/
|
||||
public static void registerPatch(Supplier<Patch> patch){
|
||||
ALL.add(patch.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the highest patch-level that is available for the given mod. If no patches were
|
||||
* registerd for the mod, this will return 0
|
||||
* @param modID The ID of the mod you want to query
|
||||
* @return The highest Patch-Level that was found
|
||||
*/
|
||||
public static int maxPatchLevel(@NotNull String modID){
|
||||
return ALL.stream()
|
||||
.filter(p-> p.getModID().equals(modID))
|
||||
.mapToInt(p->p.level)
|
||||
.max()
|
||||
.orElse(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by inheriting classes.
|
||||
*
|
||||
* Performs some sanity checks on the values and might throw a #RuntimeException if any
|
||||
* inconsistencies are found.
|
||||
*
|
||||
* @param modID The ID of the Mod you want to register a patch for. This should be your
|
||||
* ModID only. The ModID can not be {@code null} or an empty String.
|
||||
* @param level The level of the Patch. This needs to be a non-zero positive value.
|
||||
* Developers are responsible for registering their patches in the correct
|
||||
* order (with increasing levels). You are not allowed to register a new
|
||||
* Patch with a Patch-level lower or equal than
|
||||
* {@link Patch#maxPatchLevel(String)}
|
||||
*/
|
||||
protected Patch(@NotNull String modID, int level) {
|
||||
//Patchlevels need to be unique and registered in ascending order
|
||||
if (modID==null || "".equals(modID)){
|
||||
throw new RuntimeException("[INTERNAL ERROR] Patches need a valid modID!");
|
||||
}
|
||||
if (!ALL.stream().filter(p-> p.getModID().equals(modID)).noneMatch(p -> p.getLevel() >= level) || level <= 0){
|
||||
throw new RuntimeException("[INTERNAL ERROR] Patch-levels need to be created in ascending order beginning with 1.");
|
||||
}
|
||||
|
||||
|
||||
BCLib.LOGGER.info("Creating Patchlevel {} ({}, {})", level, ALL, ALL.stream().noneMatch(p -> p.getLevel() >= level));
|
||||
this.level = level;
|
||||
this.modID = modID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Patch{" +
|
||||
"level=" + getModID() + ":" + getLevel() +
|
||||
'}';
|
||||
}
|
||||
|
||||
final public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Mod-ID that registered this Patch
|
||||
* @return The ID
|
||||
*/
|
||||
final public String getModID() {
|
||||
return modID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return block data fixes. Fixes will be applied on world load if current patch-level for
|
||||
* the linked mod is lower than the {@link #level}.
|
||||
*
|
||||
* The default implementation of this method returns an empty map.
|
||||
*
|
||||
* @return The returned Map should contain the replacements. All occurences of the
|
||||
* {@code KeySet} are replaced with the associated value.
|
||||
*/
|
||||
public Map<String, String> getIDReplacements(){
|
||||
return new HashMap<String, String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates ready to use data for all currently registered patches. The list of
|
||||
* patches is selected by the current patch-level of the world.
|
||||
*
|
||||
* A {@link #Patch} with a given {@link #level} is only included if the patch-level of the
|
||||
* world is less
|
||||
* @return a new {@link MigrationData} Object.
|
||||
*/
|
||||
static MigrationData createMigrationData(PathConfig config){
|
||||
return new MigrationData(config);
|
||||
}
|
||||
|
||||
static class MigrationData{
|
||||
final Set<String> mods;
|
||||
final Map<String, String> idReplacements;
|
||||
private final PathConfig config;
|
||||
|
||||
private MigrationData(PathConfig config){
|
||||
this.config = config;
|
||||
|
||||
this.mods = Collections.unmodifiableSet(Patch.getALL().stream().map(p -> p.modID).collect(Collectors.toSet()));
|
||||
|
||||
HashMap<String, String> replacements = new HashMap<String, String>();
|
||||
for(String modID : mods){
|
||||
Patch.getALL().stream().filter(p -> p.modID.equals(modID)).forEach(patch -> {
|
||||
if (currentPatchLevel(modID) < patch.level) {
|
||||
replacements.putAll(patch.getIDReplacements());
|
||||
LOGGER.info("Applying " + patch);
|
||||
} else {
|
||||
LOGGER.info("Ignoring " + patch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.idReplacements = Collections.unmodifiableMap(replacements);
|
||||
}
|
||||
|
||||
final public void markApplied(){
|
||||
for(String modID : mods){
|
||||
LOGGER.info("Updating Patch-Level for '{}' from {} to {} -> {}",
|
||||
modID,
|
||||
currentPatchLevel(modID),
|
||||
Patch.maxPatchLevel(modID),
|
||||
config.setInt(Configs.MAIN_PATCH_CATEGORY, modID, Patch.maxPatchLevel(modID))
|
||||
);
|
||||
}
|
||||
|
||||
config.saveChanges();
|
||||
}
|
||||
|
||||
public int currentPatchLevel(@NotNull String modID){
|
||||
return config.getInt(Configs.MAIN_PATCH_CATEGORY, modID, 0);
|
||||
}
|
||||
|
||||
public boolean hasAnyFixes(){
|
||||
return idReplacements.size()>0;
|
||||
}
|
||||
|
||||
public boolean replaceStringFromIDs(@NotNull CompoundTag tag, @NotNull String key){
|
||||
if (!tag.contains(key)) return false;
|
||||
|
||||
final String val = tag.getString(key);
|
||||
final String replace = idReplacements.get(val);
|
||||
|
||||
if (replace != null){
|
||||
LOGGER.warning("Replacing ID '{}' with '{}'.", val, replace);
|
||||
tag.putString(key, replace);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final Logger LOGGER = new Logger("DataFixerAPI");
|
||||
|
||||
public static void fixData(SessionConfig config) {
|
||||
if (true || !Configs.MAIN_CONFIG.getBoolean(Configs.MAIN_PATCH_CATEGORY, "applyPatches", true)) {
|
||||
LOGGER.info("World Patches are disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
final File dir = config.levelFolder;
|
||||
Patch.MigrationData data = Patch.createMigrationData(config);
|
||||
if (!data.hasAnyFixes()) {
|
||||
LOGGER.info("Everything up to date");
|
||||
return;
|
||||
}
|
||||
|
||||
List<File> regions = getAllRegions(dir, null);
|
||||
regions.parallelStream().forEach((file) -> {
|
||||
try {
|
||||
LOGGER.info("Inspecting " + file);
|
||||
boolean[] changed = new boolean[1];
|
||||
RegionFile region = new RegionFile(file, file.getParentFile(), true);
|
||||
for (int x = 0; x < 32; x++) {
|
||||
for (int z = 0; z < 32; z++) {
|
||||
ChunkPos pos = new ChunkPos(x, z);
|
||||
changed[0] = false;
|
||||
if (region.hasChunk(pos)) {
|
||||
DataInputStream input = region.getChunkDataInputStream(pos);
|
||||
CompoundTag root = NbtIo.read(input);
|
||||
// if ((root.toString().contains("betternether") || root.toString().contains("bclib")) && root.toString().contains("chest")) {
|
||||
// NbtIo.write(root, new File(file.toString() + "-" + x + "-" + z + ".nbt"));
|
||||
// }
|
||||
input.close();
|
||||
|
||||
ListTag tileEntities = root.getCompound("Level").getList("TileEntities", 10);
|
||||
fixItemArrayWithID(tileEntities, changed, data, true);
|
||||
|
||||
ListTag sections = root.getCompound("Level").getList("Sections", 10);
|
||||
sections.forEach((tag) -> {
|
||||
ListTag palette = ((CompoundTag) tag).getList("Palette", 10);
|
||||
palette.forEach((blockTag) -> {
|
||||
CompoundTag blockTagCompound = ((CompoundTag) blockTag);
|
||||
changed[0] = data.replaceStringFromIDs(blockTagCompound, "Name");
|
||||
});
|
||||
});
|
||||
if (changed[0]) {
|
||||
LOGGER.warning("Writing '{}': {}/{}", file, x, z);
|
||||
DataOutputStream output = region.getChunkDataOutputStream(pos);
|
||||
NbtIo.write(root, output);
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
data.markApplied();
|
||||
}
|
||||
|
||||
private static boolean fixItemArrayWithID(ListTag items, boolean[] changed, Patch.MigrationData data, boolean recursive) {
|
||||
items.forEach(inTag -> {
|
||||
final CompoundTag tag = (CompoundTag) inTag;
|
||||
|
||||
changed[0] |= data.replaceStringFromIDs(tag, "id");
|
||||
|
||||
if (recursive && tag.contains("Items")) {
|
||||
changed[0] |= fixItemArrayWithID(tag.getList("Items", 10), changed, data, true);
|
||||
}
|
||||
});
|
||||
|
||||
return changed[0];
|
||||
}
|
||||
|
||||
private static List<File> getAllRegions(File dir, List<File> list) {
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
for (File file : dir.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
getAllRegions(file, list);
|
||||
}
|
||||
else if (file.isFile() && file.getName().endsWith(".mca")) {
|
||||
list.add(file);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public abstract static class Patch {
|
||||
private static List<Patch> ALL = new ArrayList<>(10);
|
||||
private final int level;
|
||||
@NotNull
|
||||
private final String modID;
|
||||
|
||||
static List<Patch> getALL() {
|
||||
return ALL;
|
||||
}
|
||||
|
||||
/**
|
||||
* register a new Patch
|
||||
*
|
||||
* @param patch A #Supplier that will instantiate the new Patch Object
|
||||
*/
|
||||
public static void registerPatch(Supplier<Patch> patch) {
|
||||
ALL.add(patch.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the highest patch-level that is available for the given mod. If no patches were
|
||||
* registerd for the mod, this will return 0
|
||||
*
|
||||
* @param modID The ID of the mod you want to query
|
||||
* @return The highest Patch-Level that was found
|
||||
*/
|
||||
public static int maxPatchLevel(@NotNull String modID) {
|
||||
return ALL.stream().filter(p -> p.getModID().equals(modID)).mapToInt(p -> p.level).max().orElse(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by inheriting classes.
|
||||
* <p>
|
||||
* Performs some sanity checks on the values and might throw a #RuntimeException if any
|
||||
* inconsistencies are found.
|
||||
*
|
||||
* @param modID The ID of the Mod you want to register a patch for. This should be your
|
||||
* ModID only. The ModID can not be {@code null} or an empty String.
|
||||
* @param level The level of the Patch. This needs to be a non-zero positive value.
|
||||
* Developers are responsible for registering their patches in the correct
|
||||
* order (with increasing levels). You are not allowed to register a new
|
||||
* Patch with a Patch-level lower or equal than
|
||||
* {@link Patch#maxPatchLevel(String)}
|
||||
*/
|
||||
protected Patch(@NotNull String modID, int level) {
|
||||
//Patchlevels need to be unique and registered in ascending order
|
||||
if (modID == null || "".equals(modID)) {
|
||||
throw new RuntimeException("[INTERNAL ERROR] Patches need a valid modID!");
|
||||
}
|
||||
if (!ALL.stream().filter(p -> p.getModID().equals(modID)).noneMatch(p -> p.getLevel() >= level) || level <= 0) {
|
||||
throw new RuntimeException("[INTERNAL ERROR] Patch-levels need to be created in ascending order beginning with 1.");
|
||||
}
|
||||
|
||||
|
||||
BCLib.LOGGER.info("Creating Patchlevel {} ({}, {})", level, ALL, ALL.stream().noneMatch(p -> p.getLevel() >= level));
|
||||
this.level = level;
|
||||
this.modID = modID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Patch{" + "level=" + getModID() + ":" + getLevel() + '}';
|
||||
}
|
||||
|
||||
final public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Mod-ID that registered this Patch
|
||||
*
|
||||
* @return The ID
|
||||
*/
|
||||
final public String getModID() {
|
||||
return modID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return block data fixes. Fixes will be applied on world load if current patch-level for
|
||||
* the linked mod is lower than the {@link #level}.
|
||||
* <p>
|
||||
* The default implementation of this method returns an empty map.
|
||||
*
|
||||
* @return The returned Map should contain the replacements. All occurences of the
|
||||
* {@code KeySet} are replaced with the associated value.
|
||||
*/
|
||||
public Map<String, String> getIDReplacements() {
|
||||
return new HashMap<String, String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates ready to use data for all currently registered patches. The list of
|
||||
* patches is selected by the current patch-level of the world.
|
||||
* <p>
|
||||
* A {@link #Patch} with a given {@link #level} is only included if the patch-level of the
|
||||
* world is less
|
||||
*
|
||||
* @return a new {@link MigrationData} Object.
|
||||
*/
|
||||
static MigrationData createMigrationData(PathConfig config) {
|
||||
return new MigrationData(config);
|
||||
}
|
||||
|
||||
static class MigrationData {
|
||||
final Set<String> mods;
|
||||
final Map<String, String> idReplacements;
|
||||
private final PathConfig config;
|
||||
|
||||
private MigrationData(PathConfig config) {
|
||||
this.config = config;
|
||||
|
||||
this.mods = Collections.unmodifiableSet(Patch.getALL().stream().map(p -> p.modID).collect(Collectors.toSet()));
|
||||
|
||||
HashMap<String, String> replacements = new HashMap<String, String>();
|
||||
for (String modID : mods) {
|
||||
Patch.getALL().stream().filter(p -> p.modID.equals(modID)).forEach(patch -> {
|
||||
if (currentPatchLevel(modID) < patch.level) {
|
||||
replacements.putAll(patch.getIDReplacements());
|
||||
LOGGER.info("Applying " + patch);
|
||||
}
|
||||
else {
|
||||
LOGGER.info("Ignoring " + patch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.idReplacements = Collections.unmodifiableMap(replacements);
|
||||
}
|
||||
|
||||
final public void markApplied() {
|
||||
for (String modID : mods) {
|
||||
LOGGER.info("Updating Patch-Level for '{}' from {} to {} -> {}", modID, currentPatchLevel(modID), Patch.maxPatchLevel(modID), config.setInt(Configs.MAIN_PATCH_CATEGORY, modID, Patch.maxPatchLevel(modID)));
|
||||
}
|
||||
|
||||
config.saveChanges();
|
||||
}
|
||||
|
||||
public int currentPatchLevel(@NotNull String modID) {
|
||||
return config.getInt(Configs.MAIN_PATCH_CATEGORY, modID, 0);
|
||||
}
|
||||
|
||||
public boolean hasAnyFixes() {
|
||||
return idReplacements.size() > 0;
|
||||
}
|
||||
|
||||
public boolean replaceStringFromIDs(@NotNull CompoundTag tag, @NotNull String key) {
|
||||
if (!tag.contains(key)) return false;
|
||||
|
||||
final String val = tag.getString(key);
|
||||
final String replace = idReplacements.get(val);
|
||||
|
||||
if (replace != null) {
|
||||
LOGGER.warning("Replacing ID '{}' with '{}'.", val, replace);
|
||||
tag.putString(key, replace);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package ru.bclib.blocks;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -14,9 +10,13 @@ import net.minecraft.world.level.material.MaterialColor;
|
|||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import ru.bclib.client.models.BlockModelProvider;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Base class for a default Block.
|
||||
*
|
||||
* <p>
|
||||
* This Block-Type will:
|
||||
* <ul>
|
||||
* <li>Drop itself</li>
|
||||
|
@ -26,15 +26,16 @@ import ru.bclib.client.models.BlockModelProvider;
|
|||
public class BaseBlock extends Block implements BlockModelProvider {
|
||||
/**
|
||||
* Creates a new Block with the passed properties
|
||||
*
|
||||
* @param settings The properties of the Block.
|
||||
*/
|
||||
public BaseBlock(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>
|
||||
* This implementation will drop the Block itself
|
||||
*/
|
||||
@Override
|
||||
|
@ -42,29 +43,30 @@ public class BaseBlock extends Block implements BlockModelProvider {
|
|||
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>
|
||||
* This implementation will load the Block-Model and return it as the Item-Model
|
||||
*/
|
||||
@Override
|
||||
public BlockModel getItemModel(ResourceLocation blockId) {
|
||||
return getBlockModel(blockId, defaultBlockState());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is used internally.
|
||||
*
|
||||
* <p>
|
||||
* It is called from Block-Contructors, to allow the augmentation of the blocks
|
||||
* preset properties.
|
||||
*
|
||||
* <p>
|
||||
* For example in {@link BaseLeavesBlock#BaseLeavesBlock(Block, MaterialColor, Consumer)}
|
||||
*
|
||||
* @param customizeProperties A {@link Consumer} to call with the preset properties
|
||||
* @param settings The properties as created by the Block
|
||||
* @param settings The properties as created by the Block
|
||||
* @return The reconfigured {@code settings}
|
||||
*/
|
||||
static FabricBlockSettings acceptAndReturn(Consumer<FabricBlockSettings> customizeProperties, FabricBlockSettings settings){
|
||||
static FabricBlockSettings acceptAndReturn(Consumer<FabricBlockSettings> customizeProperties, FabricBlockSettings settings) {
|
||||
customizeProperties.accept(settings);
|
||||
return settings;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package ru.bclib.blocks;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
|
@ -25,29 +20,25 @@ import ru.bclib.client.render.BCLRenderLayer;
|
|||
import ru.bclib.interfaces.IRenderTyped;
|
||||
import ru.bclib.util.MHelper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, IRenderTyped {
|
||||
private final Block sapling;
|
||||
|
||||
private static FabricBlockSettings makeLeaves(MaterialColor color){
|
||||
return FabricBlockSettings
|
||||
.copyOf(Blocks.OAK_LEAVES)
|
||||
.mapColor(color)
|
||||
.breakByTool(FabricToolTags.HOES)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.breakByHand(true)
|
||||
.allowsSpawning((state, world, pos, type) -> false)
|
||||
.suffocates((state, world, pos) -> false)
|
||||
.blockVision((state, world, pos) -> false);
|
||||
|
||||
private static FabricBlockSettings makeLeaves(MaterialColor color) {
|
||||
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(color).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).breakByHand(true).allowsSpawning((state, world, pos, type) -> false).suffocates((state, world, pos) -> false).blockVision((state, world, pos) -> false);
|
||||
}
|
||||
|
||||
|
||||
public BaseLeavesBlock(Block sapling, MaterialColor color, Consumer<FabricBlockSettings> customizeProperties) {
|
||||
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color)));
|
||||
this.sapling = sapling;
|
||||
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color)));
|
||||
this.sapling = sapling;
|
||||
}
|
||||
|
||||
public BaseLeavesBlock(Block sapling, MaterialColor color, int light, Consumer<FabricBlockSettings> customizeProperties) {
|
||||
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).luminance(light)));
|
||||
this.sapling = sapling;
|
||||
|
||||
public BaseLeavesBlock(Block sapling, MaterialColor color, int light, Consumer<FabricBlockSettings> customizeProperties) {
|
||||
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).luminance(light)));
|
||||
this.sapling = sapling;
|
||||
}
|
||||
|
||||
public BaseLeavesBlock(Block sapling, MaterialColor color) {
|
||||
|
|
|
@ -3,16 +3,20 @@ package ru.bclib.blocks.properties;
|
|||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@Deprecated
|
||||
public class StringProperty extends Property<String> {
|
||||
private final Set<String> values;
|
||||
|
||||
|
||||
public static StringProperty create(String name, String... values) {
|
||||
return new StringProperty(name, values);
|
||||
}
|
||||
|
||||
|
||||
protected StringProperty(String string, String... values) {
|
||||
super(string, String.class);
|
||||
this.values = Sets.newHashSet(values);
|
||||
|
@ -21,31 +25,32 @@ public class StringProperty extends Property<String> {
|
|||
public void addValue(String name) {
|
||||
values.add(name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<String> getPossibleValues() {
|
||||
return Collections.unmodifiableSet(values);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName(String comparable) {
|
||||
return comparable;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<String> getValue(String string) {
|
||||
if (values.contains(string)) {
|
||||
return Optional.of(string);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int generateHashCode() {
|
||||
return super.generateHashCode() + Objects.hashCode(values);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package ru.bclib.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.config.ConfigKeeper.BooleanEntry;
|
||||
|
@ -11,12 +9,14 @@ import ru.bclib.config.ConfigKeeper.IntegerEntry;
|
|||
import ru.bclib.config.ConfigKeeper.RangeEntry;
|
||||
import ru.bclib.config.ConfigKeeper.StringEntry;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class Config {
|
||||
protected final ConfigKeeper keeper;
|
||||
|
||||
protected abstract void registerEntries();
|
||||
|
||||
public Config(String modID, String group){
|
||||
|
||||
public Config(String modID, String group) {
|
||||
this(modID, group, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
package ru.bclib.config;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.util.JsonFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import ru.bclib.util.JsonFactory;
|
||||
|
||||
public final class ConfigKeeper {
|
||||
private final Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
|
||||
private final JsonObject configObject;
|
||||
|
@ -26,7 +24,7 @@ public final class ConfigKeeper {
|
|||
public ConfigKeeper(String modID, String group) {
|
||||
this(modID, group, null);
|
||||
}
|
||||
|
||||
|
||||
protected ConfigKeeper(String modID, String group, File path) {
|
||||
this.writer = new ConfigWriter(modID, group, path);
|
||||
this.configObject = writer.load();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package ru.bclib.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ConfigKey {
|
||||
private final String path[];
|
||||
private final String entry;
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package ru.bclib.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import ru.bclib.util.JsonFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ConfigWriter {
|
||||
private final static Path GAME_CONFIG_DIR = FabricLoader.getInstance().getConfigDir();
|
||||
|
||||
|
@ -18,14 +17,9 @@ public class ConfigWriter {
|
|||
public ConfigWriter(String modID, String configFile) {
|
||||
this(modID, configFile, null);
|
||||
}
|
||||
|
||||
|
||||
public ConfigWriter(String modID, String configFile, File configFolder) {
|
||||
this.configFile = new File(
|
||||
(configFolder==null
|
||||
? GAME_CONFIG_DIR.resolve(modID).toFile()
|
||||
: new File(configFolder, modID)),
|
||||
configFile + ".json"
|
||||
);
|
||||
this.configFile = new File((configFolder == null ? GAME_CONFIG_DIR.resolve(modID).toFile() : new File(configFolder, modID)), configFile + ".json");
|
||||
File parent = this.configFile.getParentFile();
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs();
|
||||
|
|
|
@ -5,7 +5,7 @@ import ru.bclib.BCLib;
|
|||
public class Configs {
|
||||
public static final PathConfig MAIN_CONFIG = new PathConfig(BCLib.MOD_ID, "main");
|
||||
public static final String MAIN_PATCH_CATEGORY = "patches";
|
||||
|
||||
|
||||
public static final PathConfig RECIPE_CONFIG = new PathConfig(BCLib.MOD_ID, "recipes");
|
||||
|
||||
public static void save() {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package ru.bclib.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.config.ConfigKeeper.Entry;
|
||||
import ru.bclib.config.ConfigKeeper.FloatRange;
|
||||
import ru.bclib.config.ConfigKeeper.IntegerRange;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PathConfig extends Config {
|
||||
|
||||
public PathConfig(String modID, String group) {
|
||||
this(modID, group, null);
|
||||
}
|
||||
|
||||
|
||||
protected PathConfig(String modID, String group, File path) {
|
||||
super(modID, group, path);
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
package ru.bclib.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import ru.bclib.BCLib;
|
||||
|
||||
public class SessionConfig extends PathConfig{
|
||||
private static File getWorldFolder(LevelStorageSource.LevelStorageAccess session, ServerLevel world){
|
||||
File dir = session.getDimensionPath(world.dimension());
|
||||
if (!new File(dir, "level.dat").exists()) {
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
import java.io.File;
|
||||
|
||||
public final File levelFolder;
|
||||
|
||||
public SessionConfig(String modID, String group, LevelStorageSource.LevelStorageAccess session, ServerLevel world) {
|
||||
super(modID, group, new File(getWorldFolder(session, world), BCLib.MOD_ID));
|
||||
|
||||
this.levelFolder = new File(getWorldFolder(session, world), BCLib.MOD_ID);
|
||||
}
|
||||
public class SessionConfig extends PathConfig {
|
||||
private static File getWorldFolder(LevelStorageSource.LevelStorageAccess session, ServerLevel world) {
|
||||
File dir = session.getDimensionPath(world.dimension());
|
||||
if (!new File(dir, "level.dat").exists()) {
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
public final File levelFolder;
|
||||
|
||||
public SessionConfig(String modID, String group, LevelStorageSource.LevelStorageAccess session, ServerLevel world) {
|
||||
super(modID, group, new File(getWorldFolder(session, world), BCLib.MOD_ID));
|
||||
|
||||
this.levelFolder = new File(getWorldFolder(session, world), BCLib.MOD_ID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,36 +3,26 @@ package ru.bclib.mixin.client;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.WinScreen;
|
||||
import net.minecraft.client.main.GameConfig;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.Musics;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import ru.bclib.interfaces.IColorProvider;
|
||||
import ru.bclib.util.MHelper;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private BlockColors blockColors;
|
||||
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
private ItemColors itemColors;
|
||||
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void bclib_onMCInit(GameConfig args, CallbackInfo info) {
|
||||
Registry.BLOCK.forEach(block -> {
|
||||
|
|
|
@ -25,11 +25,7 @@ public class TextureAtlasMixin {
|
|||
bclib_modifyAtlas = resourceLocation.toString().equals("minecraft:textures/atlas/blocks.png");
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
@Inject(method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", at = @At("HEAD"), cancellable = true)
|
||||
private void bclib_loadSprite(ResourceManager resourceManager, TextureAtlasSprite.Info spriteInfo, int atlasWidth, int atlasHeight, int maxLevel, int posX, int posY, CallbackInfoReturnable<TextureAtlasSprite> info) {
|
||||
ResourceLocation location = spriteInfo.name();
|
||||
if (bclib_modifyAtlas && location.getPath().startsWith("block")) {
|
||||
|
|
|
@ -7,7 +7,6 @@ import net.minecraft.world.InteractionResult;
|
|||
import net.minecraft.world.item.BoneMealItem;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeCategory;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
@ -18,12 +17,9 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import ru.bclib.api.BiomeAPI;
|
||||
import ru.bclib.api.BonemealAPI;
|
||||
import ru.bclib.api.TagAPI;
|
||||
import ru.bclib.util.BlocksHelper;
|
||||
import ru.bclib.util.MHelper;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Mixin(BoneMealItem.class)
|
||||
public class BoneMealItemMixin {
|
||||
private static final MutableBlockPos bclib_BLOCK_POS = new MutableBlockPos();
|
||||
|
@ -139,7 +135,7 @@ public class BoneMealItemMixin {
|
|||
Block terrain = BonemealAPI.getSpreadable(state.getBlock());
|
||||
if (center.is(terrain)) {
|
||||
if (haveSameProperties(state, center)) {
|
||||
for (Property property: center.getProperties()) {
|
||||
for (Property property : center.getProperties()) {
|
||||
state = state.setValue(property, center.getValue(property));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
package ru.bclib.mixin.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
@ -27,6 +22,11 @@ import ru.bclib.api.DataFixerAPI2;
|
|||
import ru.bclib.api.WorldDataAPI;
|
||||
import ru.bclib.config.SessionConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(ServerLevel.class)
|
||||
public abstract class ServerLevelMixin extends Level {
|
||||
private static String bclib_lastWorld = null;
|
||||
|
|
|
@ -44,7 +44,7 @@ public class BaseBlockEntities {
|
|||
public static Block[] getFurnaces() {
|
||||
return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
|
||||
}
|
||||
|
||||
|
||||
public static boolean registerSpecialBlock(Block block) {
|
||||
if (block instanceof BaseChestBlock) {
|
||||
BaseBlockEntities.CHEST.registerBlock(block);
|
||||
|
@ -62,7 +62,7 @@ public class BaseBlockEntities {
|
|||
BaseBlockEntities.FURNACE.registerBlock(block);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ public class JsonFactory {
|
|||
|
||||
/**
|
||||
* Loads {@link JsonObject} from resource location using Minecraft resource manager. Can be used to load JSON from resourcepacks and resources.
|
||||
*
|
||||
* @param location {@link ResourceLocation} to JSON file
|
||||
* @return {@link JsonObject}
|
||||
*/
|
||||
|
@ -70,7 +71,8 @@ public class JsonFactory {
|
|||
stream.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {}
|
||||
catch (IOException ex) {
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package ru.bclib.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
@ -14,24 +10,27 @@ import net.minecraft.world.item.Item;
|
|||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Utility functions to manage Minecraft Tags
|
||||
*/
|
||||
public class TagHelper {
|
||||
private static final Map<ResourceLocation, Set<ResourceLocation>> TAGS_BLOCK = Maps.newConcurrentMap();
|
||||
private static final Map<ResourceLocation, Set<ResourceLocation>> TAGS_ITEM = Maps.newConcurrentMap();
|
||||
|
||||
|
||||
/**
|
||||
* Adds one Tag to multiple Blocks.
|
||||
*
|
||||
* <p>
|
||||
* Example:
|
||||
* <pre>{@code Tag.Named<Block> DIMENSION_STONE = makeBlockTag("mymod", "dim_stone");
|
||||
* TagHelper.addTag(DIMENSION_STONE, Blocks.END_STONE, Blocks.NETHERRACK);}</pre>
|
||||
*
|
||||
* <p>
|
||||
* The call will reserve the Tag. The Tag is added to the blocks once
|
||||
* {@link #apply(String, Map)} was executed.
|
||||
*
|
||||
* @param tag The new Tag
|
||||
* @param tag The new Tag
|
||||
* @param blocks One or more blocks that should receive the Tag.
|
||||
*/
|
||||
public static void addTag(Tag.Named<Block> tag, Block... blocks) {
|
||||
|
@ -44,18 +43,18 @@ public class TagHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds one Tag to multiple Items.
|
||||
*
|
||||
* <p>
|
||||
* Example:
|
||||
* <pre>{@code Tag.Named<Item> METALS = makeBlockTag("mymod", "metals");
|
||||
* TagHelper.addTag(METALS, Items.IRON_INGOT, Items.GOLD_INGOT, Items.COPPER_INGOT);}</pre>
|
||||
*
|
||||
* <p>
|
||||
* The call will reserve the Tag. The Tag is added to the items once
|
||||
* {@link #apply(String, Map)} was executed.
|
||||
*
|
||||
* @param tag The new Tag
|
||||
* @param tag The new Tag
|
||||
* @param items One or more item that should receive the Tag.
|
||||
*/
|
||||
public static void addTag(Tag.Named<Item> tag, ItemLike... items) {
|
||||
|
@ -68,12 +67,12 @@ public class TagHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds multiple Tags to one Item.
|
||||
*
|
||||
* <p>
|
||||
* The call will reserve the Tags. The Tags are added to the Item once
|
||||
* * {@link #apply(String, Map)} was executed.
|
||||
* * {@link #apply(String, Map)} was executed.
|
||||
*
|
||||
* @param item The Item that will receive all Tags
|
||||
* @param tags One or more Tags
|
||||
|
@ -84,15 +83,15 @@ public class TagHelper {
|
|||
addTag(tag, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds multiple Tags to one Block.
|
||||
*
|
||||
* <p>
|
||||
* The call will reserve the Tags. The Tags are added to the Block once
|
||||
* * {@link #apply(String, Map)} was executed.
|
||||
* * {@link #apply(String, Map)} was executed.
|
||||
*
|
||||
* @param block The Block that will receive all Tags
|
||||
* @param tags One or more Tags
|
||||
* @param tags One or more Tags
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static void addTags(Block block, Tag.Named<Block>... tags) {
|
||||
|
@ -100,28 +99,27 @@ public class TagHelper {
|
|||
addTag(tag, block);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds all {@code ids} to the {@code builder}.
|
||||
*
|
||||
* @param builder
|
||||
* @param ids
|
||||
*
|
||||
* @return The Builder passed as {@code builder}.
|
||||
*/
|
||||
public static Tag.Builder apply(Tag.Builder builder, Set<ResourceLocation> ids) {
|
||||
ids.forEach(value -> builder.addElement(value, "Better End Code"));
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Automatically called in {@link net.minecraft.tags.TagLoader#loadAndBuild(ResourceManager)}.
|
||||
*
|
||||
* <p>
|
||||
* In most cases there is no need to call this Method manually.
|
||||
*
|
||||
* @param directory The name of the Tag-directory. Should be either <i>"tags/blocks"</i> or
|
||||
* <i>"tags/items"</i>.
|
||||
* @param tagsMap The map that will hold the registered Tags
|
||||
*
|
||||
* <i>"tags/items"</i>.
|
||||
* @param tagsMap The map that will hold the registered Tags
|
||||
* @return The {@code tagsMap} Parameter.
|
||||
*/
|
||||
public static Map<ResourceLocation, Tag.Builder> apply(String directory, Map<ResourceLocation, Tag.Builder> tagsMap) {
|
||||
|
|
Loading…
Reference in a new issue