Skip to content

Commit

Permalink
add owo lib support
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Dec 13, 2021
1 parent d930d96 commit a0d5636
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 65 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ 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 {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
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"
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 24 additions & 12 deletions src/main/java/artifality/ArtifalityMod.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand All @@ -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){
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/artifality/item/ArtifactSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -16,21 +16,21 @@ 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) {
this.rarity = rarity;
return this;
}

public ArtifactSettings setChance(float chance) {
this.chance = chance;
public ArtifactSettings nonCrateItem() {
this.isCrateLoot = false;
return this;
}

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/artifality/item/ArtifalityItemGroup.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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);
});
}
}

8 changes: 4 additions & 4 deletions src/main/java/artifality/mixin/client/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
33 changes: 13 additions & 20 deletions src/main/java/artifality/registry/ArtifalityEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
});
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/artifality/util/EffectsUtils.java
Original file line number Diff line number Diff line change
@@ -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<StatusEffect> 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<StatusEffect> NEGATIVE_EFFECTS = new ArrayList<>(Arrays.asList(
StatusEffects.LEVITATION, StatusEffects.MINING_FATIGUE, StatusEffects.SLOWNESS,
StatusEffects.POISON, StatusEffects.WEAKNESS, StatusEffects.WITHER
));
public static final List<StatusEffect> POSITIVE_EFFECTS = Lists.newArrayList(
FIRE_RESISTANCE, REGENERATION, STRENGTH,
SPEED, ABSORPTION, HASTE,
JUMP_BOOST, RESISTANCE
);
public static final List<StatusEffect> 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()));
Expand All @@ -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));
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/artifality/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,6 @@
"misc.artifality.placeable": "Placeable",

"misc.artifality.discord": "<Join Our Discord Server>",
"misc.artifality.wiki": "<Check Out the Wiki for More Info>"
"misc.artifality.wiki": "<Check Out the Wiki for More Info>",
"itemGroup.artifality.items.button.discord": "Join Our Discord"
}

0 comments on commit a0d5636

Please sign in to comment.