use of net.silentchaos512.gear.config.Config in project SilentGems by SilentChaos512.
the class ToolHelper method addExampleRecipe.
public static void addExampleRecipe(Item item, EnumMaterialTier[] tiers, String[] lines, Object... extraParams) {
// New ingredient-based recipes
ConfigOptionToolClass config = item instanceof ITool ? ((ITool) item).getConfig() : null;
for (EnumMaterialTier tier : tiers) {
// Only add recipes for valid tiers
if (config != null && !config.validTiers.contains(tier))
continue;
// Head parts for tier
List<ItemStack> heads = new ArrayList<>();
for (ToolPart part : ToolPartRegistry.getMains()) if (!part.isBlacklisted(part.getCraftingStack()) && part.getTier() == tier && StackHelper.isValid(part.getCraftingStack()))
heads.add(part.getCraftingStack());
IngredientSL headIngredient = IngredientSL.from(heads.toArray(new ItemStack[0]));
// Rods for tier
List<ItemStack> rods = new ArrayList<>();
for (ToolPart part : ToolPartRegistry.getRods()) if (!part.isBlacklisted(part.getCraftingStack()) && part.getCompatibleTiers().contains(tier))
rods.add(part.getCraftingStack());
IngredientSL rodIngredient = IngredientSL.from(rods.toArray(new ItemStack[0]));
// Armor frames
List<ItemStack> frames = new ArrayList<>();
if (item instanceof ItemGemArmor) {
EntityEquipmentSlot slot = ((ItemGemArmor) item).armorType;
for (ToolPart part : ToolPartRegistry.getValues()) if (part instanceof ArmorPartFrame && ((ArmorPartFrame) part).getSlot() == slot && part.getTier() == tier && !part.isBlacklisted(part.getCraftingStack()))
frames.add(part.getCraftingStack());
}
IngredientSL frameIngredient = IngredientSL.from(frames.toArray(new ItemStack[0]));
ResourceLocation recipeName = new ResourceLocation(item.getRegistryName().toString() + "_" + tier.name().toLowerCase() + "_example");
ItemStack result = new ItemStack(item);
NBTTagCompound tags = new NBTTagCompound();
tags.setInteger(NBT_EXAMPLE_TOOL_TIER, tier.ordinal());
result.setTagCompound(tags);
// Super ugly, but I've got never better at the moment.
List<Object> params = new ArrayList<>();
for (String line : lines) params.add(line);
if (recipeContainsKey(lines, "h")) {
params.add('h');
params.add(headIngredient);
}
if (recipeContainsKey(lines, "r")) {
params.add('r');
params.add(rodIngredient);
}
if (recipeContainsKey(lines, "a")) {
params.add('a');
params.add(frameIngredient);
}
for (Object obj : extraParams) params.add(obj);
EXAMPLE_RECIPES.add(SilentGems.registry.recipes.makeShaped(recipeName.getResourcePath(), result, params.toArray()));
}
}
use of net.silentchaos512.gear.config.Config in project SilentGems by SilentChaos512.
the class GemsWorldGenerator method selectState.
/**
* Selects an IBlockState for the config. For gems, it will normally choose one randomly each call. For essence ores,
* it selects the appropriate ore.
*
* @param config
* @param random
* @return
*/
protected IBlockState selectState(ConfigOptionOreGen config, Random random, World world, int posX, int posZ) {
if (config == GemsConfig.WORLD_GEN_GEMS) {
EnumGem gem;
if (GemsConfig.GEM_REGIONS_ENABLED) {
// Gem Regions
long dimension = (long) world.provider.getDimension();
long cx = (long) posX / 16 / GemsConfig.GEM_REGIONS_SIZE;
long cz = (long) posZ / 16 / GemsConfig.GEM_REGIONS_SIZE;
long seed = (world.getSeed() << 40L) | ((dimension & 0xFF) << 32L) | ((cz & 0xFFFF) << 16L) | (cx & 0xFFFF);
Random regionRandom = new Random(seed);
EnumGem firstGem = EnumGem.values()[regionRandom.nextInt(16)];
EnumGem secondGem = EnumGem.values()[regionRandom.nextInt(16)];
if (regionRandom.nextFloat() < GemsConfig.GEM_REGIONS_SECOND_GEM_CHANCE && random.nextBoolean()) {
gem = secondGem;
} else {
gem = firstGem;
}
} else {
// Classic logic
int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS)).getMeta();
gem = EnumGem.values()[meta];
}
return ModBlocks.gemOre.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
} else if (config == GemsConfig.WORLD_GEN_CHAOS) {
return ModBlocks.essenceOre.getDefaultState().withProperty(BlockEssenceOre.VARIANT, BlockEssenceOre.Type.CHAOS);
} else if (config == GemsConfig.WORLD_GEN_GEMS_DARK) {
int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS_DARK)).getMeta();
EnumGem gem = EnumGem.values()[meta];
return ModBlocks.gemOreDark.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
} else if (config == GemsConfig.WORLD_GEN_ENDER) {
return ModBlocks.essenceOre.getDefaultState().withProperty(BlockEssenceOre.VARIANT, BlockEssenceOre.Type.ENDER);
} else if (config == GemsConfig.WORLD_GEN_GEMS_LIGHT) {
int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS_LIGHT)).getMeta();
EnumGem gem = EnumGem.values()[meta];
return ModBlocks.gemOreLight.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
} else {
SilentGems.logHelper.severe("GemsWorldGenerator - Unknown ore config: " + config.name);
return null;
}
}
use of net.silentchaos512.gear.config.Config in project Silent-Gear by SilentChaos512.
the class GearData method tryRecalculateStats.
@SuppressWarnings({ "OverlyLongMethod", "OverlyComplexMethod" })
private static void tryRecalculateStats(ItemStack gear, @Nullable Player player) {
if (checkNonGearItem(gear, "recalculateStats"))
return;
getUUID(gear);
TraitHelper.activateTraits(gear, 0f, (trait, level, value) -> {
trait.onRecalculatePre(new TraitActionContext(player, level, gear));
return 0f;
});
ICoreItem item = (ICoreItem) gear.getItem();
PartDataList parts = getConstructionParts(gear);
CompoundTag propertiesCompound = getData(gear, NBT_ROOT_PROPERTIES);
if (!propertiesCompound.contains(NBT_LOCK_STATS))
propertiesCompound.putBoolean(NBT_LOCK_STATS, false);
String playerName = player != null ? player.getScoreboardName() : "somebody";
String playersItemText = String.format("%s's %s", playerName, gear.getHoverName().getString());
final boolean statsUnlocked = !propertiesCompound.getBoolean(NBT_LOCK_STATS);
final boolean partsListValid = !parts.isEmpty() && !parts.getMains().isEmpty();
if (statsUnlocked && partsListValid) {
// We should recalculate the item's stats!
if (player != null) {
SilentGear.LOGGER.debug("Recalculating for {}", playersItemText);
}
clearCachedData(gear);
propertiesCompound.putString("ModVersion", SilentGear.getVersion());
Map<ITrait, Integer> traits = TraitHelper.getTraits(gear, item.getGearType(), parts);
// Get all stat modifiers from all parts and item class modifiers
StatModifierMap stats = getStatModifiers(gear, item, parts);
// For debugging
Map<ItemStat, Float> oldStatValues = getCurrentStatsForDebugging(gear);
// Cache traits in properties compound as well
ListTag traitList = new ListTag();
traits.forEach((trait, level) -> traitList.add(trait.write(level)));
propertiesCompound.put("Traits", traitList);
propertiesCompound.remove(NBT_SYNERGY);
// Calculate and write stats
int maxDamage = gear.getMaxDamage() > 0 ? gear.getMaxDamage() : 1;
final float damageRatio = Mth.clamp((float) gear.getDamageValue() / maxDamage, 0f, 1f);
CompoundTag statsCompound = new CompoundTag();
for (ItemStat stat : ItemStats.allStatsOrderedExcluding(item.getExcludedStats(gear))) {
StatGearKey key = StatGearKey.of(stat, item.getGearType());
Collection<StatInstance> modifiers = stats.get(key);
GearType statGearType = stats.getMostSpecificKey(key).getGearType();
final float initialValue = stat.compute(stat.getBaseValue(), true, item.getGearType(), statGearType, modifiers);
// Allow traits to modify stat
final float withTraits = TraitHelper.activateTraits(gear, initialValue, (trait, level, val) -> {
TraitActionContext context = new TraitActionContext(player, level, gear);
return trait.onGetStat(context, stat, val, damageRatio);
});
final float value = Config.Common.getStatWithMultiplier(stat, withTraits);
if (!Mth.equal(value, 0f) || stats.containsKey(key)) {
ResourceLocation statId = Objects.requireNonNull(stat.getRegistryName());
// Remove old keys
propertiesCompound.remove(statId.getPath());
statsCompound.putFloat(statId.toString(), stat.clampValue(value));
}
}
// Put missing relevant stats in the map to avoid recalculate stats packet spam
for (ItemStat stat : item.getRelevantStats(gear)) {
String statKey = stat.getStatId().toString();
if (!statsCompound.contains(statKey)) {
statsCompound.putFloat(statKey, stat.getDefaultValue());
}
}
propertiesCompound.put(NBT_STATS, statsCompound);
if (player != null) {
printStatsForDebugging(gear, stats, oldStatValues);
}
// Remove enchantments if mod is configured to. Must be done before traits add enchantments!
if (gear.getOrCreateTag().contains("Enchantments") && Config.Common.forceRemoveEnchantments.get()) {
SilentGear.LOGGER.debug("Forcibly removing all enchantments from {} as per config settings", playersItemText);
gear.removeTagKey("Enchantments");
}
// Remove trait-added enchantments then let traits re-add them
EnchantmentTrait.removeTraitEnchantments(gear);
TraitHelper.activateTraits(gear, 0f, (trait, level, value) -> {
trait.onRecalculatePost(new TraitActionContext(player, level, gear));
return 0f;
});
} else {
SilentGear.LOGGER.debug("Not recalculating stats for {}", playersItemText);
}
// Update rendering info even if we didn't update stats
updateRenderingInfo(gear, parts);
}
Aggregations