From a0d5636d6bc4d44a5a3759af643db437743d9f90 Mon Sep 17 00:00:00 2001 From: PinkGoosik Date: Mon, 13 Dec 2021 15:57:05 +0500 Subject: [PATCH] add owo lib support --- build.gradle | 4 +- gradle.properties | 1 + src/main/java/artifality/ArtifalityMod.java | 36 ++++++++++------ .../artifality/item/ArtifactSettings.java | 14 +++---- .../artifality/item/ArtifalityItemGroup.java | 42 +++++++++++++++++++ .../mixin/client/ItemStackMixin.java | 8 ++-- .../artifality/registry/ArtifalityEvents.java | 33 ++++++--------- .../java/artifality/util/EffectsUtils.java | 36 +++++++--------- .../assets/artifality/lang/en_us.json | 3 +- 9 files changed, 112 insertions(+), 65 deletions(-) create mode 100644 src/main/java/artifality/item/ArtifalityItemGroup.java diff --git a/build.gradle b/build.gradle index 44d3061..3eb1b65 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ repositories { maven { url "https://ladysnake.jfrog.io/artifactory/mods" } //CCA maven { url "https://maven.terraformersmc.com" } //modmenu, trinkets maven { url "https://maven.pinkgoosik.ru" } //cosmetica + maven { url 'https://maven.wispforest.io' } //owo lib } dependencies { @@ -22,7 +23,8 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation "dev.emi:trinkets:${trinkets_version}" + modImplementation "dev.emi:trinkets:${project.trinkets_version}" + modImplementation "com.glisco:owo-lib:${project.owo_version}" modImplementation "ru.pinkgoosik:cosmetica:0.3.2-1.17.1-fabric" include "ru.pinkgoosik:cosmetica:0.3.2-1.17.1-fabric" diff --git a/gradle.properties b/gradle.properties index 8d1687e..63076a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,3 +14,4 @@ org.gradle.jvmargs=-Xmx1G # Dependencies fabric_version=0.43.1+1.17 trinkets_version=3.0.4 + owo_version=0.3.2+1.17 diff --git a/src/main/java/artifality/ArtifalityMod.java b/src/main/java/artifality/ArtifalityMod.java index 4823943..9251ec9 100644 --- a/src/main/java/artifality/ArtifalityMod.java +++ b/src/main/java/artifality/ArtifalityMod.java @@ -1,8 +1,11 @@ package artifality; +import artifality.item.ArtifalityItemGroup; import artifality.registry.*; +import com.glisco.owo.itemgroup.OwoItemGroup; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.enchantment.EnchantmentLevelEntry; import net.minecraft.item.EnchantedBookItem; import net.minecraft.item.ItemGroup; @@ -16,18 +19,7 @@ public class ArtifalityMod implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger("Artifality"); public static final String MOD_ID = "artifality"; - - public static final ItemGroup ITEMS_ITEM_GROUP = FabricItemGroupBuilder.create(newId("items")) - .appendItems(groupStacks -> { - ArtifalityItems.ITEMS.forEach((id, item) -> groupStacks.add(item.getDefaultStack())); - ArtifalityBlocks.ITEMS.forEach((id, item) -> groupStacks.add(item.getDefaultStack())); - ArtifalityEnchants.ENCHANTMENTS.forEach((id, enchantment) -> { - ItemStack book = new ItemStack(Items.ENCHANTED_BOOK); - EnchantedBookItem.addEnchantment(book, new EnchantmentLevelEntry(enchantment, enchantment.getMaxLevel())); - groupStacks.add(book); - }); - }) - .icon(ArtifalityItems.WRATH_CRYSTAL_WAND::getDefaultStack).build(); + public static ItemGroup ITEM_GROUP; @Override public void onInitialize() { @@ -36,6 +28,26 @@ public void onInitialize() { ArtifalityEnchants.init(); ArtifalityFeatures.init(); ArtifalityEvents.init(); + initItemGroup(); + } + + private static void initItemGroup() { + if(FabricLoader.getInstance().isModLoaded("owo")){ + ITEM_GROUP = new ArtifalityItemGroup(newId("items")); + ((OwoItemGroup)ITEM_GROUP).initialize(); + }else { + ITEM_GROUP = FabricItemGroupBuilder.create(newId("items")) + .appendItems(stacks -> { + ArtifalityItems.ITEMS.forEach((id, item) -> stacks.add(item.getDefaultStack())); + ArtifalityBlocks.ITEMS.forEach((id, item) -> stacks.add(item.getDefaultStack())); + ArtifalityEnchants.ENCHANTMENTS.forEach((id, enchantment) -> { + ItemStack book = new ItemStack(Items.ENCHANTED_BOOK); + EnchantedBookItem.addEnchantment(book, new EnchantmentLevelEntry(enchantment, enchantment.getMaxLevel())); + stacks.add(book); + }); + }) + .icon(ArtifalityItems.WRATH_CRYSTAL_WAND::getDefaultStack).build(); + } } public static Identifier newId(String path){ diff --git a/src/main/java/artifality/item/ArtifactSettings.java b/src/main/java/artifality/item/ArtifactSettings.java index aea6658..e4e28ee 100644 --- a/src/main/java/artifality/item/ArtifactSettings.java +++ b/src/main/java/artifality/item/ArtifactSettings.java @@ -6,7 +6,7 @@ public class ArtifactSettings { private final FabricItemSettings settings; private ArtifactRarity rarity = ArtifactRarity.COMMON; - private float chance = 1; + private boolean isCrateLoot = true; public ArtifactSettings(){ settings = new FabricItemSettings(); @@ -16,12 +16,12 @@ public ArtifactRarity getRarity() { return rarity; } - public FabricItemSettings getItemSettings() { - return settings; + public boolean isCrateLoot() { + return isCrateLoot; } - public float getChance() { - return chance; + public FabricItemSettings getItemSettings() { + return settings; } public ArtifactSettings setRarity(ArtifactRarity rarity) { @@ -29,8 +29,8 @@ public ArtifactSettings setRarity(ArtifactRarity rarity) { return this; } - public ArtifactSettings setChance(float chance) { - this.chance = chance; + public ArtifactSettings nonCrateItem() { + this.isCrateLoot = false; return this; } diff --git a/src/main/java/artifality/item/ArtifalityItemGroup.java b/src/main/java/artifality/item/ArtifalityItemGroup.java new file mode 100644 index 0000000..5d85411 --- /dev/null +++ b/src/main/java/artifality/item/ArtifalityItemGroup.java @@ -0,0 +1,42 @@ +package artifality.item; + +import artifality.registry.ArtifalityBlocks; +import artifality.registry.ArtifalityEnchants; +import artifality.registry.ArtifalityItems; +import com.glisco.owo.itemgroup.OwoItemGroup; +import com.glisco.owo.itemgroup.gui.ItemGroupButton; +import net.minecraft.enchantment.EnchantmentLevelEntry; +import net.minecraft.item.EnchantedBookItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DefaultedList; + +public class ArtifalityItemGroup extends OwoItemGroup { + + public ArtifalityItemGroup(Identifier id) { + super(id); + } + + @Override + protected void setup() { + addButton(ItemGroupButton.discord("https://discord.gg/DcemWeskeZ")); + } + + @Override + public ItemStack createIcon() { + return ArtifalityItems.WRATH_CRYSTAL_WAND.getDefaultStack(); + } + + @Override + public void appendStacks(DefaultedList stacks) { + ArtifalityItems.ITEMS.forEach((id, item) -> stacks.add(item.getDefaultStack())); + ArtifalityBlocks.ITEMS.forEach((id, item) -> stacks.add(item.getDefaultStack())); + ArtifalityEnchants.ENCHANTMENTS.forEach((id, enchantment) -> { + ItemStack book = new ItemStack(Items.ENCHANTED_BOOK); + EnchantedBookItem.addEnchantment(book, new EnchantmentLevelEntry(enchantment, enchantment.getMaxLevel())); + stacks.add(book); + }); + } +} + diff --git a/src/main/java/artifality/mixin/client/ItemStackMixin.java b/src/main/java/artifality/mixin/client/ItemStackMixin.java index 941e516..0e13fd5 100644 --- a/src/main/java/artifality/mixin/client/ItemStackMixin.java +++ b/src/main/java/artifality/mixin/client/ItemStackMixin.java @@ -16,13 +16,13 @@ public class ItemStackMixin { private static final UUID ATTACK_SPEED_MODIFIER_ID = UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"); @Redirect(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/attribute/EntityAttributeModifier;getValue()D")) - double lunarDamageFunctionality(EntityAttributeModifier entityAttributeModifier){ - if(entityAttributeModifier.getId().equals(ATTACK_SPEED_MODIFIER_ID)){ + double getValue(EntityAttributeModifier attributeModifier){ + if(attributeModifier.getId().equals(ATTACK_SPEED_MODIFIER_ID)){ if (EnchantmentHelper.get(self).containsKey(ArtifalityEnchants.LUNAR_DAMAGE)){ int level = EnchantmentHelper.getLevel(ArtifalityEnchants.LUNAR_DAMAGE, self); - return entityAttributeModifier.getValue() - (level + 2) / 20.0F; + return attributeModifier.getValue() - (level + 2) / 20.0F; } } - return entityAttributeModifier.getValue(); + return attributeModifier.getValue(); } } diff --git a/src/main/java/artifality/registry/ArtifalityEvents.java b/src/main/java/artifality/registry/ArtifalityEvents.java index e341991..92bfb82 100644 --- a/src/main/java/artifality/registry/ArtifalityEvents.java +++ b/src/main/java/artifality/registry/ArtifalityEvents.java @@ -15,27 +15,20 @@ public class ArtifalityEvents { public static void init() { ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.register((world, entity, killedEntity) -> { if (killedEntity instanceof ElementalExtension extension) { - if (extension.artifality$isElemental()) { - if ((world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT))) { - CrystalElement element = extension.artifality$getElement(); - ItemStack stack; - int count = world.random.nextInt(4) + 1; - if (element.equals(CrystalElements.LIFE)) { - stack = new ItemStack(ArtifalityItems.LIFE_CRYSTAL, count); - } else if (element.equals(CrystalElements.LUNAR)) { - stack = new ItemStack(ArtifalityItems.LUNAR_CRYSTAL, count); - } else if (element.equals(CrystalElements.WRATH)) { - stack = new ItemStack(ArtifalityItems.WRATH_CRYSTAL, count); - } else { - stack = new ItemStack(ArtifalityItems.INCREMENTAL_CRYSTAL, count); - } - killedEntity.dropStack(stack); + if (world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT) && extension.artifality$isElemental()) { + CrystalElement element = extension.artifality$getElement(); + ItemStack stack; + int count = world.random.nextInt(4) + 1; + if (element.equals(CrystalElements.LIFE)) stack = new ItemStack(ArtifalityItems.LIFE_CRYSTAL, count); + else if (element.equals(CrystalElements.LUNAR)) stack = new ItemStack(ArtifalityItems.LUNAR_CRYSTAL, count); + else if (element.equals(CrystalElements.WRATH)) stack = new ItemStack(ArtifalityItems.WRATH_CRYSTAL, count); + else stack = new ItemStack(ArtifalityItems.INCREMENTAL_CRYSTAL, count); + killedEntity.dropStack(stack); - BlockPos pos = killedEntity.getBlockPos(); - ExperienceOrbEntity.spawn(world, Vec3d.ofCenter(pos), 5); - ExperienceOrbEntity.spawn(world, Vec3d.ofCenter(pos), 5 + world.random.nextInt(6)); - ExperienceOrbEntity.spawn(world, Vec3d.ofCenter(pos), 5 + world.random.nextInt(11)); - } + BlockPos pos = killedEntity.getBlockPos(); + ExperienceOrbEntity.spawn(world, Vec3d.ofCenter(pos), 5); + ExperienceOrbEntity.spawn(world, Vec3d.ofCenter(pos), 5 + world.random.nextInt(6)); + ExperienceOrbEntity.spawn(world, Vec3d.ofCenter(pos), 5 + world.random.nextInt(11)); } } }); diff --git a/src/main/java/artifality/util/EffectsUtils.java b/src/main/java/artifality/util/EffectsUtils.java index 340f0d1..c1f412e 100644 --- a/src/main/java/artifality/util/EffectsUtils.java +++ b/src/main/java/artifality/util/EffectsUtils.java @@ -1,24 +1,24 @@ package artifality.util; +import com.google.common.collect.Lists; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; +import static net.minecraft.entity.effect.StatusEffects.*; -import java.util.ArrayList; -import java.util.Arrays; +import java.util.List; import java.util.Random; public class EffectsUtils { - public static final ArrayList POSITIVE_EFFECTS = new ArrayList<>(Arrays.asList( - StatusEffects.FIRE_RESISTANCE, StatusEffects.REGENERATION, StatusEffects.STRENGTH, - StatusEffects.SPEED, StatusEffects.ABSORPTION, StatusEffects.HASTE, - StatusEffects.JUMP_BOOST, StatusEffects.RESISTANCE - )); - public static final ArrayList NEGATIVE_EFFECTS = new ArrayList<>(Arrays.asList( - StatusEffects.LEVITATION, StatusEffects.MINING_FATIGUE, StatusEffects.SLOWNESS, - StatusEffects.POISON, StatusEffects.WEAKNESS, StatusEffects.WITHER - )); + public static final List POSITIVE_EFFECTS = Lists.newArrayList( + FIRE_RESISTANCE, REGENERATION, STRENGTH, + SPEED, ABSORPTION, HASTE, + JUMP_BOOST, RESISTANCE + ); + public static final List NEGATIVE_EFFECTS = Lists.newArrayList( + LEVITATION, MINING_FATIGUE, SLOWNESS, + POISON, WEAKNESS, WITHER + ); public static StatusEffect getRandomPositive(){ return POSITIVE_EFFECTS.get(new Random().nextInt(POSITIVE_EFFECTS.size())); @@ -31,20 +31,16 @@ public static StatusEffect getRandomNegative(){ public static void ticking(LivingEntity entity, StatusEffect effect){ if (!entity.hasStatusEffect(effect)) { entity.addStatusEffect(new StatusEffectInstance(effect, 10, 0, false, false)); - } else { - if (entity.getActiveStatusEffects().get(effect).getDuration() == 1) { - entity.addStatusEffect(new StatusEffectInstance(effect, 10, 0, false, false)); - } + } else if (entity.getActiveStatusEffects().get(effect).getDuration() == 1) { + entity.addStatusEffect(new StatusEffectInstance(effect, 10, 0, false, false)); } } public static void ticking(LivingEntity entity, StatusEffect effect, int amplifier){ if (!entity.hasStatusEffect(effect)) { entity.addStatusEffect(new StatusEffectInstance(effect, 10, amplifier, true, true)); - } else { - if (entity.getActiveStatusEffects().get(effect).getDuration() == 1) { - entity.addStatusEffect(new StatusEffectInstance(effect, 10, amplifier, true, true)); - } + } else if (entity.getActiveStatusEffects().get(effect).getDuration() == 1) { + entity.addStatusEffect(new StatusEffectInstance(effect, 10, amplifier, true, true)); } } } diff --git a/src/main/resources/assets/artifality/lang/en_us.json b/src/main/resources/assets/artifality/lang/en_us.json index e1d8aca..cb8b2c5 100644 --- a/src/main/resources/assets/artifality/lang/en_us.json +++ b/src/main/resources/assets/artifality/lang/en_us.json @@ -217,5 +217,6 @@ "misc.artifality.placeable": "Placeable", "misc.artifality.discord": "", - "misc.artifality.wiki": "" + "misc.artifality.wiki": "", + "itemGroup.artifality.items.button.discord": "Join Our Discord" } \ No newline at end of file