Skip to content

Commit

Permalink
Merge pull request #9 from milkev/master
Browse files Browse the repository at this point in the history
Quick update to 1.20.x
  • Loading branch information
LemmaEOF authored Jul 18, 2023
2 parents bc9a0fa + 18119b2 commit 265fa30
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 107 deletions.
81 changes: 48 additions & 33 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,60 +1,73 @@
plugins {
id "fabric-loom" version "0.10-SNAPSHOT"
id "maven-publish"
id "com.jfrog.artifactory" version "4.15.2"
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

if(rootProject.file('private.gradle').exists()) { //Publishing details
apply from: 'private.gradle'
}

archivesBaseName = "${project.archives_base_name}"
group = "${project.maven_group}"
version = "${project.mod_version}+${project.minecraft_version}"

minecraft {
}

repositories {
mavenCentral()
maven { url "https://maven.fabricmc.net/" }
maven { url "https://server.bbkr.space/artifactory/libs-release" }
maven { url "https://jitpack.io" }
//Trinkets
maven {
name = "TerraformersMC"
url = "https://maven.terraformersmc.com/"
}
//Player Ability Lib
maven {
name = 'Ladysnake Mods'
url = 'https://ladysnake.jfrog.io/artifactory/mods'
url = 'https://maven.ladysnake.org/releases'
content {
includeGroup 'io.github.ladysnake'
includeGroupByRegex 'io\\.github\\.onyxstudios.*'
}
}
maven {
name = "TerraformersMC"
url = "https://maven.terraformersmc.com/"
//Cloth Config API
maven { url "https://maven.shedaniel.me/" }
flatDir {
dirs 'build/loom-cache'
}
// maven { url "https://maven.pkg.github.com" }
}

dependencies {
//to change the versions see the gradle.properties file
//minecraft version
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2"
//yarn mappings
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
//fabric loader
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
//fabric api
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
//trinkets
modImplementation "dev.emi:trinkets:${trinkets_version}"
//cardinal components api
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}"
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}"
//player ability lib
modImplementation "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
include "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
//config api
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
}
}

processResources {
inputs.property "version", project.version

modImplementation "com.github.emilyploszaj:trinkets:${project.trinkets_version}"
modImplementation "io.github.cottonmc:Jankson-Fabric:${project.jankson_version}"
modImplementation "io.github.ladysnake:PlayerAbilityLib:${project.pal_version}"
include "com.github.emilyploszaj:trinkets:${project.trinkets_version}"
include "io.github.ladysnake:PlayerAbilityLib:${project.pal_version}"
include "io.github.cottonmc:Jankson-Fabric:${project.jankson_version}"
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}

from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
Expand All @@ -64,6 +77,7 @@ tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

//fixes problem i had with intellij and gradle
tasks {
processResources {
setDuplicatesStrategy('include')
Expand All @@ -74,14 +88,15 @@ tasks {
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
//classifier = "sources"
from sourceSets.main.allSource
}

jar {
from "LICENSE"
}


// configure the maven publication
publishing {
publications {
Expand Down
19 changes: 10 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.18.1
yarn_build=22
loader_version=0.13.2
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21

#Fabric api
fabric_version=0.85.0+1.20.1

# Mod Properties
mod_version = 1.2.0
maven_group = space.bbkr
archives_base_name = shulkercharm

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api

fabric_version=0.46.4+1.18
trinkets_version=3.2.0
jankson_version=4.0.0+j1.2.0
pal_version=1.5.0
trinkets_version=3.7.0
pal_version=1.8.0
cardinal_components_version=5.2.1
cloth_config_version=11.0.99
63 changes: 13 additions & 50 deletions src/main/java/space/bbkr/shulkercharm/ShulkerCharm.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,39 @@
package space.bbkr.shulkercharm;

import blue.endless.jankson.Jankson;
import blue.endless.jankson.JsonElement;
import blue.endless.jankson.JsonObject;
import io.github.cottonmc.jankson.JanksonFactory;
import io.github.ladysnake.pal.AbilitySource;
import io.github.ladysnake.pal.Pal;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.registry.Registry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.FileOutputStream;

public class ShulkerCharm implements ModInitializer {
public static final String MODID = "shulkercharm";

public static final Logger logger = LogManager.getLogger();

public static final Identifier CHARM_FLIGHT_ID = new Identifier(MODID, "shulker_charm_flight");

public static final AbilitySource CHARM_FLIGHT = Pal.getAbilitySource(CHARM_FLIGHT_ID);

public static final Item SHULKER_CHARM = Registry.register(Registry.ITEM, new Identifier(MODID, "shulker_charm"), new ShulkerCharmItem(new Item.Settings().maxCount(1).rarity(Rarity.RARE).group(ItemGroup.TRANSPORTATION)));
public static final Item SHULKER_CHARM = Registry.register(Registries.ITEM, new Identifier(MODID, "shulker_charm"), new ShulkerCharmItem(new Item.Settings().maxCount(1).rarity(Rarity.RARE)));

public static ShulkerCharmConfig config;

@Override
public void onInitialize() {
config = loadConfig();
}
AutoConfig.register(ShulkerCharmConfig.class, JanksonConfigSerializer::new);

public ShulkerCharmConfig loadConfig() {
try {
Jankson jankson = JanksonFactory.createJankson();
File file = FabricLoader.getInstance().getConfigDir().resolve("shulkercharm.json5").toFile();
if (!file.exists()) saveConfig(new ShulkerCharmConfig());
JsonObject json = jankson.load(file);
ShulkerCharmConfig result = jankson.fromJson(json, ShulkerCharmConfig.class);
JsonElement jsonElementNew = jankson.toJson(new ShulkerCharmConfig());
if(jsonElementNew instanceof JsonObject){
JsonObject jsonNew = (JsonObject) jsonElementNew;
if(json.getDelta(jsonNew).size() > 0){
saveConfig(result);
}
}
return result;
} catch (Exception e) {
logger.error("[ShulkerCharm] Error loading config: {}", e.getMessage());
}
return new ShulkerCharmConfig();
}
ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register(content -> {
content.add(SHULKER_CHARM);
});

public void saveConfig(ShulkerCharmConfig config) {
try {
File file = FabricLoader.getInstance().getConfigDir().resolve("shulkercharm.json5").toFile();
JsonElement json = JanksonFactory.createJankson().toJson(config);
String result = json.toJson(true, true);
if (!file.exists()) file.createNewFile();
FileOutputStream out = new FileOutputStream(file,false);
out.write(result.getBytes());
out.flush();
out.close();
} catch (Exception e) {
logger.error("[ShulkerCharm] Error saving config: {}", e.getMessage());
config = loadConfig();
config = AutoConfig.getConfigHolder(ShulkerCharmConfig.class).getConfig();
if (config.maxEnergy != -1) {
config.maxPower = config.maxEnergy;
config.maxEnergy = -1;
}
}

Expand Down
26 changes: 16 additions & 10 deletions src/main/java/space/bbkr/shulkercharm/ShulkerCharmItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

import java.util.List;
Expand All @@ -28,7 +29,7 @@ public void tick(ItemStack stack, SlotReference slot, LivingEntity entity) {
super.tick(stack, slot, entity);
if (entity instanceof PlayerEntity player) {
int power = getPower(stack);
if (player.world.isClient) return;
if (player.getWorld().isClient) return;
if (ShulkerCharm.CHARM_FLIGHT.grants(player, VanillaAbilities.ALLOW_FLYING)) {
if (power <= 0) {
ShulkerCharm.CHARM_FLIGHT.revokeFrom(player, VanillaAbilities.ALLOW_FLYING);
Expand Down Expand Up @@ -64,27 +65,32 @@ public void onUnequip(ItemStack stack, SlotReference slot, LivingEntity entity)

@Override
public boolean isItemBarVisible(ItemStack stack) {
if (ShulkerCharm.config.rangeModifier == -1) return false;
NbtCompound tag = stack.getOrCreateNbt();
if (tag.contains("Power", NbtType.INT)) return tag.getInt("Power") != ShulkerCharm.config.maxPower;
else return true;
if (ShulkerCharm.config.rangeModifier == -1) {
return false;
}
//"-1" so that the bar doesnt show while flying at 'max charge' in range of a beacon
return getPower(stack) < getMaxDurability() - 1;
}

@Override
public int getItemBarStep(ItemStack stack) {
return Math.round(((float)getPower(stack) / (float)ShulkerCharm.config.maxPower) * 13.0F);
return Math.round((float)getPower(stack) * 13.0F / (float)getMaxDurability());
}

@Override
public int getItemBarColor(ItemStack stack) {
return 0xC7C38D;
}

public int getMaxDurability() {
return ShulkerCharm.config.maxPower;
}

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
if (context.isAdvanced()) {
int power = getPower(stack);
tooltip.add(new TranslatableText("tooltip.shulkercharm.power", power, ShulkerCharm.config.maxPower));
tooltip.add(Text.translatable("tooltip.shulkercharm.power", power, getMaxDurability()));
}
}

Expand All @@ -94,7 +100,7 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
* @return The amount of power it currently has.
*/
public int getPower(ItemStack stack) {
if (ShulkerCharm.config.rangeModifier == -1) return ShulkerCharm.config.maxPower;
if (ShulkerCharm.config.rangeModifier == -1) return getMaxDurability();
NbtCompound tag = stack.getOrCreateNbt();
if (!tag.contains("Power", NbtType.INT)) tag.putInt("Power", 0);
return tag.getInt("Power");
Expand All @@ -107,7 +113,7 @@ public int getPower(ItemStack stack) {
*/
public void setPower(ItemStack stack, int power) {
NbtCompound tag = stack.getOrCreateNbt();
tag.putInt("Power", Math.max(0, Math.min(power, ShulkerCharm.config.maxPower)));
tag.putInt("Power", Math.max(0, Math.min(power, getMaxDurability())));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"mixins.shulkercharm.json"
],
"depends": {
"fabricloader": ">=0.11.3",
"minecraft": ">=1.18.1",
"fabricloader": ">=0.14.21",
"fabric": "*",
"trinkets": ">=2.3.0",
"jankson-fabric": ">=4.0.0",
"playerabilitylib": ">=1.3.0"
"minecraft": "1.20.x",
"trinkets": ">=3.7.0",
"cloth-config2": ">=11.0.99",
"playerabilitylib": ">=1.8.0"
}
}
2 changes: 2 additions & 0 deletions src/main/resources/mixins.shulkercharm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"package": "space.bbkr.shulkercharm.mixin",
"mixins": [
"MixinBeaconBlockEntity"
],
"client": [
]
}

0 comments on commit 265fa30

Please sign in to comment.