Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
208 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package de.melanx.ultimatools; | ||
|
||
import com.electronwill.nightconfig.core.file.CommentedFileConfig; | ||
import com.electronwill.nightconfig.core.io.WritingMode; | ||
import net.minecraftforge.common.ForgeConfigSpec; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class ServerConfig { | ||
public static final ForgeConfigSpec SERVER_CONFIG; | ||
private static final ForgeConfigSpec.Builder SERVER_BUILDER = new ForgeConfigSpec.Builder(); | ||
|
||
static { | ||
init(SERVER_BUILDER); | ||
|
||
SERVER_CONFIG = SERVER_BUILDER.build(); | ||
} | ||
|
||
public static ForgeConfigSpec.ConfigValue<List<? extends String>> OVERWORLD_ORES; | ||
public static ForgeConfigSpec.ConfigValue<List<? extends String>> NETHER_ORES; | ||
public static ForgeConfigSpec.ConfigValue<List<? extends String>> ANIMALS; | ||
public static ForgeConfigSpec.ConfigValue<List<? extends String>> WATER_ANIMALS; | ||
|
||
public static void init(ForgeConfigSpec.Builder builder) { | ||
builder.push("ores"); | ||
OVERWORLD_ORES = builder.comment("All the ores for upgrading normal ores, order matters") | ||
.defineList("overworld", Arrays.asList( | ||
"minecraft:iron_ore", | ||
"minecraft:redstone_ore", | ||
"minecraft:lapis_ore", | ||
"minecraft:gold_ore", | ||
"minecraft:diamond_ore", | ||
"minecraft:emerald_ore" | ||
), (obj) -> obj instanceof String); | ||
NETHER_ORES = builder.comment("All the ores for upgrading nether ores, order matters") | ||
.defineList("nether", Arrays.asList( | ||
"minecraft:nether_quartz_ore", | ||
"minecraft:nether_gold_ore" | ||
), (obj) -> obj instanceof String); | ||
builder.pop(); | ||
|
||
builder.push("animals"); | ||
ANIMALS = builder.comment("All animals which can spawn randomly") | ||
.defineList("animals", Arrays.asList( | ||
"minecraft:bat", | ||
"minecraft:bee", | ||
"minecraft:cat", | ||
"minecraft:chicken", | ||
"minecraft:cow", | ||
"minecraft:donkey", | ||
"minecraft:fox", | ||
"minecraft:horse", | ||
"minecraft:llama", | ||
"minecraft:mule", | ||
"minecraft:mooshroom", | ||
"minecraft:ocelot", | ||
"minecraft:panda", | ||
"minecraft:parrot", | ||
"minecraft:pig", | ||
"minecraft:polar_bear", | ||
"minecraft:rabbit", | ||
"minecraft:sheep", | ||
"minecraft:turtle", | ||
"minecraft:wolf" | ||
), (obj) -> obj instanceof String); | ||
WATER_ANIMALS = builder.comment("All animals which can spawn in water randomly") | ||
.defineList("water_animals", Arrays.asList( | ||
"minecraft:cod", | ||
"minecraft:dolphin", | ||
"minecraft:pufferfish", | ||
"minecraft:salmon", | ||
"minecraft:squid", | ||
"minecraft:tropical_fish" | ||
), (obj) -> obj instanceof String); | ||
} | ||
|
||
public static void loadConfig(ForgeConfigSpec spec, Path path) { | ||
SkyblockUltimaTools.LOGGER.debug("Loading config file {}", path); | ||
final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave().writingMode(WritingMode.REPLACE).build(); | ||
configData.load(); | ||
spec.setConfig(configData); | ||
} | ||
} |
23 changes: 20 additions & 3 deletions
23
src/main/java/de/melanx/ultimatools/SkyblockUltimaTools.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
package de.melanx.ultimatools; | ||
|
||
import de.melanx.ultimatools.item.Registration; | ||
import de.melanx.ultimatools.lib.LibMisc; | ||
import de.melanx.ultimatools.lib.ListHandlers; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.fml.ModLoadingContext; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.config.ModConfig; | ||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; | ||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; | ||
import net.minecraftforge.fml.loading.FMLConfig; | ||
import net.minecraftforge.fml.loading.FMLPaths; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
@Mod(LibMisc.MODID) | ||
@Mod(SkyblockUltimaTools.MODID) | ||
public class SkyblockUltimaTools { | ||
|
||
public SkyblockUltimaTools() { | ||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ServerConfig.SERVER_CONFIG); | ||
ServerConfig.loadConfig(ServerConfig.SERVER_CONFIG, FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath()).resolve(MODID + "-server.toml")); | ||
Registration.init(); | ||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onServerStarted); | ||
} | ||
|
||
public static final ItemGroup TAB = new ItemGroup(LibMisc.MODID) { | ||
public static final String MODID = "ultimatools"; | ||
public static final Logger LOGGER = LogManager.getLogger(MODID); | ||
public static final ItemGroup TAB = new ItemGroup(MODID) { | ||
@Override | ||
public ItemStack createIcon() { | ||
return new ItemStack(Registration.ultimaGod.get()); | ||
} | ||
}; | ||
|
||
private void onServerStarted(FMLCommonSetupEvent event) { | ||
ListHandlers.reloadLists(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package de.melanx.ultimatools.lib; | ||
|
||
import de.melanx.ultimatools.ServerConfig; | ||
import de.melanx.ultimatools.SkyblockUltimaTools; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.entity.EntityClassification; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
public class ListHandlers { | ||
|
||
public static List<Block> ORES = new ArrayList<>(); | ||
public static List<Block> NETHER_ORES = new ArrayList<>(); | ||
public static List<EntityType<?>> ANIMALS = new ArrayList<>(); | ||
public static List<EntityType<?>> WATER_ANIMALS = new ArrayList<>(); | ||
|
||
public static void fillOres() { | ||
ORES.clear(); | ||
ServerConfig.OVERWORLD_ORES.get().forEach(string -> { | ||
Block block = ForgeRegistries.BLOCKS.getValue(ResourceLocation.tryCreate(string)); | ||
if (block != Blocks.AIR) { | ||
ORES.add(block); | ||
} else { | ||
SkyblockUltimaTools.LOGGER.error("Block '{}' not found", string); | ||
} | ||
}); | ||
} | ||
|
||
public static void fillNetherOres() { | ||
NETHER_ORES.clear(); | ||
ServerConfig.NETHER_ORES.get().forEach(string -> { | ||
Block block = ForgeRegistries.BLOCKS.getValue(ResourceLocation.tryCreate(string)); | ||
if (block != Blocks.AIR) { | ||
NETHER_ORES.add(block); | ||
} else { | ||
SkyblockUltimaTools.LOGGER.error("Block '{}' not found", string); | ||
} | ||
}); | ||
} | ||
|
||
public static void fillAnimals() { | ||
ANIMALS.clear(); | ||
ServerConfig.ANIMALS.get().forEach(string -> { | ||
EntityType<?> entity = ForgeRegistries.ENTITIES.getValue(ResourceLocation.tryCreate(string)); | ||
if (entity != null) { | ||
if (entity.getClassification() == EntityClassification.CREATURE || entity.getClassification() == EntityClassification.AMBIENT) { | ||
if (entity.getRegistryName().toString().equals(string)) { | ||
ANIMALS.add(entity); | ||
} else { | ||
SkyblockUltimaTools.LOGGER.error("Entity '{}' not found", string); | ||
} | ||
} else { | ||
SkyblockUltimaTools.LOGGER.error("'{}' is no animal", string); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public static void fillWaterAnimals() { | ||
WATER_ANIMALS.clear(); | ||
ServerConfig.WATER_ANIMALS.get().forEach(string -> { | ||
EntityType<?> entity = ForgeRegistries.ENTITIES.getValue(ResourceLocation.tryCreate(string)); | ||
if (entity != null) { | ||
if (entity.getClassification() == EntityClassification.WATER_CREATURE || entity.getClassification() == EntityClassification.WATER_AMBIENT) { | ||
if (entity.getRegistryName().toString().equals(string)) { | ||
WATER_ANIMALS.add(entity); | ||
} else { | ||
SkyblockUltimaTools.LOGGER.error("Entity '{}' not found", string); | ||
} | ||
} else { | ||
SkyblockUltimaTools.LOGGER.error("'{}' is no water animal", string); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public static void reloadLists() { | ||
fillOres(); | ||
fillNetherOres(); | ||
fillAnimals(); | ||
fillWaterAnimals(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters