use of nex.NetherEx in project NetherEx by LogicTechCorp.
the class AdditionalBiomeManager method init.
public static void init(File directory) {
try {
if (!directory.exists()) {
directory.mkdir();
}
LOGGER.info("Copying the Biome List Directory to the config folder.");
if (NetherEx.IS_DEV_ENV) {
FileUtils.copyDirectory(new File(NetherEx.class.getResource("/assets/nex/biome_lists").getFile()), directory);
} else {
FileUtil.extractFromJar("/assets/nex/biome_lists", directory.getPath());
}
} catch (IOException e) {
LOGGER.fatal("The attempt to copy the Biome List Directory to the config folder was unsuccessful.");
LOGGER.fatal(e);
}
Gson gson = new Gson();
List<File> additionalBiomeFiles = Lists.newArrayList(directory.listFiles());
try {
for (File additionalBiomeFile : additionalBiomeFiles) {
String jsonText = Files.toString(additionalBiomeFile, Charsets.UTF_8);
AdditionalBiomeList biomeList = gson.fromJson(jsonText, AdditionalBiomeList.class);
LOGGER.info("Adding biomes from the " + biomeList.getName() + ".");
for (AdditionalBiomeMod biomeMod : biomeList.getMods()) {
for (AdditionalBiome additionalBiome : biomeMod.getBiomes()) {
ResourceLocation biomeRegistryName = new ResourceLocation(biomeMod.getName() + ":" + additionalBiome.getName());
Biome biome = Biome.REGISTRY.getObject(biomeRegistryName);
if (biome == null) {
continue;
}
int weight = additionalBiome.getWeight();
AdditionalBiome.OceanBlock oceanBlock = additionalBiome.getOceanBlock();
if (oceanBlock == null) {
oceanBlock = new AdditionalBiome.OceanBlock("minecraft:air", 0);
}
Block block = Block.getBlockFromName(oceanBlock.getName().isEmpty() ? "minecraft:air" : oceanBlock.getName());
int meta = oceanBlock.getMeta();
IBlockState state = block.getStateFromMeta(meta);
NetherExBiomeType type = NetherExBiomeType.getFromString(additionalBiome.getType());
NetherExBiomes.addBiome(biome, weight, state, type);
LOGGER.info("The " + biome.getBiomeName() + " biome from the " + biomeList.getName() + " was added to the Nether.");
}
}
}
} catch (IOException e) {
LOGGER.fatal("NetherEx was unable to read the Biome lists.");
LOGGER.fatal(e);
}
}
use of nex.NetherEx in project NetherEx by LogicTechCorp.
the class TradeListManager method init.
public static void init(File directory) {
for (TradeCareer.EnumType career : TradeCareer.EnumType.values()) {
offerLists.put(career, Maps.newHashMap());
}
try {
LOGGER.info("Copying the Trade List Directory to the config folder.");
if (NetherEx.IS_DEV_ENV) {
FileUtils.copyDirectory(new File(NetherEx.class.getResource("/assets/nex/trade_lists").getFile()), directory);
} else {
FileUtil.extractFromJar("/assets/nex/trade_lists", directory.getPath());
}
} catch (IOException e) {
LOGGER.fatal("The attempt to copy the Trade List Directory to the config folder was unsuccessful.");
LOGGER.fatal(e);
}
try {
Gson gson = new Gson();
List<File> tradeFiles = Lists.newArrayList(directory.listFiles());
for (File tradeFile : tradeFiles) {
String jsonText = Files.toString(tradeFile, Charsets.UTF_8);
TradeList tradeList = gson.fromJson(jsonText, TradeList.class);
LOGGER.info("Adding trades from the " + tradeList.getName() + ".");
for (TradeProfession profession : tradeList.getProfessions()) {
for (TradeCareer career : profession.getCareers()) {
for (TradeOffer offer : career.getTrades()) {
ItemStack outputStack;
TradeOffer.Output output = offer.getOutput();
String outputId = output.getName();
int outputMeta = output.getMeta();
TradeOffer.Amount outputAmount = output.getAmount();
List<TradeOffer.Enchantment> outputEnchantments = output.getEnchantments();
TradeOffer.Display outputDisplay = output.getDisplay();
if (Item.getByNameOrId(outputId) != null) {
outputStack = new ItemStack(Item.getByNameOrId(outputId), 1, outputMeta);
} else if (Block.getBlockFromName(outputId) != null) {
outputStack = new ItemStack(Block.getBlockFromName(outputId), 1, outputMeta);
} else {
continue;
}
if (outputEnchantments == null) {
outputEnchantments = Lists.newArrayList();
}
if (outputDisplay != null) {
if (!Strings.isNullOrEmpty(outputDisplay.getName())) {
outputStack.setStackDisplayName(outputDisplay.getName());
}
if (outputDisplay.getLore().size() > 0) {
NBTUtil.setTag(outputStack);
NBTTagList loreList = new NBTTagList();
for (String lore : outputDisplay.getLore()) {
loreList.appendTag(new NBTTagString(lore));
}
NBTTagCompound displayCompound = new NBTTagCompound();
displayCompound.setTag("Lore", loreList);
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("display", displayCompound);
NBTUtil.setTag(outputStack, compound);
}
}
ItemStack inputStackA;
TradeOffer.Input inputA = offer.getInputA();
String inputAId = inputA.getName();
int inputAMeta = inputA.getMeta();
TradeOffer.Amount inputAAmount = inputA.getAmount();
if (Item.getByNameOrId(inputAId) != null) {
inputStackA = new ItemStack(Item.getByNameOrId(inputAId), 1, inputAMeta);
} else if (Block.getBlockFromName(inputAId) != null) {
inputStackA = new ItemStack(Block.getBlockFromName(inputAId), 1, inputAMeta);
} else {
continue;
}
ItemStack inputStackB;
TradeOffer.Input inputB = offer.getInputB();
if (inputB == null) {
inputB = new TradeOffer.Input("minecraft:air", 0, new TradeOffer.Amount(1, 1));
}
String inputBId = inputB.getName();
int inputBMeta = inputB.getMeta();
TradeOffer.Amount inputBAmount = inputB.getAmount();
if (Item.getByNameOrId(inputBId) != null) {
inputStackB = new ItemStack(Item.getByNameOrId(inputBId), 1, inputBMeta);
} else if (Block.getBlockFromName(inputBId) != null) {
inputStackB = new ItemStack(Block.getBlockFromName(inputBId), 1, inputBMeta);
} else {
continue;
}
TradeOffer.Amount offerAmount = offer.getAmount();
Trade trade = new Trade(outputStack, outputAmount, inputStackA, inputAAmount, inputStackB, inputBAmount, offerAmount, outputEnchantments);
offerLists.get(TradeCareer.EnumType.fromCareer(career)).computeIfAbsent(offer.getLevel(), k -> Lists.newArrayList()).add(trade);
}
}
}
}
} catch (IOException e) {
LOGGER.fatal("NetherEx was unable to read the Trade lists.");
LOGGER.fatal(e);
}
}
Aggregations