Skip to content

Commit

Permalink
Merged 1.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Jun 8, 2023
1 parent 3899bfd commit 9fa75e1
Show file tree
Hide file tree
Showing 83 changed files with 1,517 additions and 414 deletions.
25 changes: 16 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'

version = '1.1.5'
group = 'com.majruszsaccessories' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'majruszs-accessories-1.19.2'
version = versions_mod
group = 'com.majruszsaccessories'
archivesBaseName = "majruszs-accessories-${versions_minecraft}"

// Mojang ships Java 16 to end users in 1.17+ instead of Java 8 in 1.16 or lower, so your mod should target Java 16.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
Expand All @@ -25,7 +25,7 @@ compileJava {
}

minecraft {
mappings channel: 'official', version: '1.19.2'
mappings channel: 'official', version: versions_minecraft

accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.

Expand Down Expand Up @@ -80,12 +80,19 @@ repositories {
}
}

processResources {
filesMatching('META-INF/mods.toml') {
expand project.properties
}
outputs.upToDateWhen { false }
}

dependencies {
minecraft 'net.minecraftforge:forge:1.19.2-43.2.0'
implementation fg.deobf( 'com.mlib:majrusz-library-1.19.2:4.0.0' )
implementation fg.deobf( 'com.mlib:majruszs-difficulty-1.19.2:1.7.4' )
runtimeOnly fg.deobf( "top.theillusivec4.curios:curios-forge:1.19.2-5.1.1.0" )
compileOnly fg.deobf( "top.theillusivec4.curios:curios-forge:1.19.2-5.1.1.0:api" )
minecraft "net.minecraftforge:forge:${versions_minecraft}-${versions_forge}"
implementation fg.deobf( "com.mlib:majrusz-library-${versions_minecraft}:${versions_mlib}" )
implementation fg.deobf( "com.mlib:majruszs-difficulty-${versions_minecraft}:${versions_difficulty}" )
runtimeOnly fg.deobf( "top.theillusivec4.curios:curios-forge:${versions_curios}" )
compileOnly fg.deobf( "top.theillusivec4.curios:curios-forge:${versions_curios}:api" )
}

jar {
Expand Down
13 changes: 12 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.daemon=false
versions_minecraft=1.19.2
versions_minecraft_range=[1.19.2,1.20)
versions_forge=43.2.0
versions_forge_range=[43.2.0,)
versions_mod=1.2.0
versions_mlib=4.3.0
versions_mlib_range=[4.3.0,5.0.0)
versions_difficulty=1.7.4
versions_difficulty_range=[1.7.4,)
versions_curios=1.19.2-5.1.1.0
versions_curios_range=[1.19.2-5.1.1.0,)
Binary file not shown.
88 changes: 61 additions & 27 deletions src/main/java/com/majruszsaccessories/AccessoryHolder.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.majruszsaccessories;

import com.majruszsaccessories.accessories.AccessoryBase;
import com.majruszsaccessories.items.AccessoryItem;
import com.majruszsaccessories.accessories.AccessoryItem;
import com.majruszsaccessories.boosters.BoosterItem;
import com.mlib.Random;
import com.mlib.Utility;
import com.mlib.config.DoubleConfig;
import com.mlib.config.IntegerConfig;
import com.mlib.math.Range;
Expand All @@ -16,42 +17,47 @@
import top.theillusivec4.curios.api.SlotResult;

import java.util.Optional;
import java.util.function.Predicate;

public class AccessoryHolder {
public static final Range< Float > BONUS_RANGE = new Range<>( -0.6f, 0.6f );
final ItemStack itemStack;
final AccessoryItem item;

public static AccessoryHolder find( LivingEntity entity, AccessoryItem item ) {
public static AccessoryHolder find( LivingEntity entity, Predicate< ItemStack > predicate ) {
if( Integration.isCuriosInstalled() ) {
Optional< SlotResult > slotResult = CuriosApi.getCuriosHelper().findFirstCurio( entity, item );
Optional< SlotResult > slotResult = CuriosApi.getCuriosHelper().findFirstCurio( entity, predicate );
if( slotResult.isPresent() ) {
return new AccessoryHolder( slotResult.get().stack() );
}
} else {
ItemStack itemStack = entity.getOffhandItem();
if( itemStack.is( item ) ) {
if( predicate.test( itemStack ) ) {
return new AccessoryHolder( itemStack );
}
}

return new AccessoryHolder( ItemStack.EMPTY );
}

public static boolean hasAccessory( LivingEntity entity, AccessoryItem item ) {
return find( entity, item ).isValid();
public static AccessoryHolder find( LivingEntity entity, AccessoryItem item ) {
return find( entity, itemStack->itemStack.is( item ) );
}

public static AccessoryHolder create( AccessoryItem item ) {
return new AccessoryHolder( new ItemStack( item ) );
public static AccessoryHolder find( LivingEntity entity, BoosterItem item ) {
return find( entity, itemStack->AccessoryHolder.create( itemStack ).hasBoosterTag( item ) );
}

public static AccessoryHolder create( AccessoryItem item, float bonus ) {
return new AccessoryHolder( new ItemStack( item ) ).setBonus( bonus );
public static boolean hasAccessory( LivingEntity entity, AccessoryItem item ) {
return find( entity, item ).isValid();
}

public static AccessoryHolder create( AccessoryItem item, Range< Float > bonus ) {
return new AccessoryHolder( new ItemStack( item ) ).setBonus( bonus );
public static boolean hasBooster( LivingEntity entity, BoosterItem item ) {
return find( entity, item ).isValid();
}

public static AccessoryHolder create( AccessoryItem item ) {
return new AccessoryHolder( new ItemStack( item ) );
}

public static AccessoryHolder create( ItemStack itemStack ) {
Expand Down Expand Up @@ -79,8 +85,8 @@ public static Rarity getItemRarity( float bonus ) {
}

public static float randomBonus() {
float gaussianRandom = ( float )Mth.clamp( Random.nextGaussian() / 3.0f, -1.0f, 1.0f ); // random value from range [-1.0; 1.0] with mean ~= 0.0 and standard deviation ~= 0.3333..
float ratio = ( gaussianRandom + 1.0f ) / 2.0f; // random value from range [0.0; 1.0] with mean ~= 0.5 and standard deviation ~= 0.1666..
float gaussianRandom = ( float )Mth.clamp( Random.nextGaussian() / 4.0f, -1.0f, 1.0f ); // random value from range [-1.0; 1.0] with mean ~= 0.0 and standard deviation ~= 0.25
float ratio = ( gaussianRandom + 1.0f ) / 2.0f; // random value from range [0.0; 1.0] with mean ~= 0.5 and standard deviation ~= 0.125

return Mth.lerp( ratio, BONUS_RANGE.from, BONUS_RANGE.to );
}
Expand All @@ -90,6 +96,13 @@ private AccessoryHolder( ItemStack itemStack ) {
this.item = itemStack.getItem() instanceof AccessoryItem item ? item : null;
}

public AccessoryHolder copy() {
AccessoryHolder copy = new AccessoryHolder( new ItemStack( this.item ) );
copy.setBonus( this.getBonus() );

return copy;
}

public int apply( IntegerConfig config, int multiplier ) {
return config.getRange().clamp( Math.round( ( 1.0f + multiplier * this.getBonus() ) * config.get() ) );
}
Expand All @@ -108,8 +121,8 @@ public float apply( DoubleConfig config ) {

public AccessoryHolder setRandomBonus() {
if( this.hasBonusRangeTag() ) {
float minBonus = this.getTagValue( Tags.VALUE_MIN );
float maxBonus = this.getTagValue( Tags.VALUE_MAX );
float minBonus = this.getFloatTag( Tags.VALUE_MIN );
float maxBonus = this.getFloatTag( Tags.VALUE_MAX );

return this.setTagValue( Tags.VALUE, Mth.lerp( Random.nextFloat( 0.0f, 1.0f ), minBonus, maxBonus ) );
} else {
Expand All @@ -122,23 +135,23 @@ public AccessoryHolder setBonus( float bonus ) {
}

public AccessoryHolder setBonus( Range< Float > bonus ) {
return this.setTagValue( Tags.VALUE_MIN, bonus.from ).setTagValue( Tags.VALUE_MAX, bonus.to );
if( ( bonus.to - bonus.from ) > 1e-5f ) {
return this.setTagValue( Tags.VALUE_MIN, bonus.from ).setTagValue( Tags.VALUE_MAX, bonus.to );
} else {
return this.setBonus( bonus.from );
}
}

public Optional< AccessoryBase > findAccessoryBase() {
return Registries.OBJECTS.stream()
.filter( obj->obj instanceof AccessoryBase )
.map( obj->( AccessoryBase )obj )
.filter( base->base.is( this.item ) )
.findAny();
public AccessoryHolder setBooster( BoosterItem item ) {
return this.setTagValue( Tags.BOOSTER, Utility.getRegistryString( item ) );
}

public float getBonus() {
return this.getTagValue( Tags.VALUE );
return this.getFloatTag( Tags.VALUE );
}

public Range< Float > getBonusRange() {
return new Range<>( this.getTagValue( Tags.VALUE_MIN ), this.getTagValue( Tags.VALUE_MAX ) );
return new Range<>( this.getFloatTag( Tags.VALUE_MIN ), this.getFloatTag( Tags.VALUE_MAX ) );
}

public ItemStack getItemStack() {
Expand Down Expand Up @@ -177,22 +190,43 @@ public boolean hasMaxBonus() {
return this.getBonus() == BONUS_RANGE.to;
}

public boolean hasBoosterTag( BoosterItem item ) {
return Utility.getRegistryString( item ).equals( this.getStringTag( Tags.BOOSTER ) );
}

public boolean hasBoosterTag() {
return !this.getStringTag( Tags.BOOSTER ).isEmpty();
}

private AccessoryHolder setTagValue( String tag, float value ) {
this.itemStack.getOrCreateTagElement( Tags.BONUS ).putFloat( tag, Math.round( 100.0f * value ) / 100.0f );

return this;
}

private float getTagValue( String tag ) {
private AccessoryHolder setTagValue( String tag, String value ) {
this.itemStack.getOrCreateTagElement( Tags.BONUS ).putString( tag, value );

return this;
}

private float getFloatTag( String tag ) {
CompoundTag itemTag = this.itemStack.getTagElement( Tags.BONUS );

return itemTag != null ? itemTag.getFloat( tag ) : 0.0f;
}

private String getStringTag( String tag ) {
CompoundTag itemTag = this.itemStack.getTagElement( Tags.BONUS );

return itemTag != null ? itemTag.getString( tag ) : "";
}

static final class Tags {
static final String BONUS = "Bonus";
static final String VALUE = "Value";
static final String VALUE_MIN = "ValueMin";
static final String VALUE_MAX = "ValueMax";
static final String BOOSTER = "Booster";
}
}
25 changes: 18 additions & 7 deletions src/main/java/com/majruszsaccessories/Registries.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.majruszsaccessories;

import com.majruszsaccessories.items.*;
import com.majruszsaccessories.accessories.AccessoryItem;
import com.majruszsaccessories.boosters.BoosterItem;
import com.majruszsaccessories.items.BoosterOverlay;
import com.majruszsaccessories.recipes.AccessoryRecipe;
import com.majruszsaccessories.recipes.BoostAccessoriesRecipe;
import com.majruszsaccessories.recipes.CombineAccessoriesRecipe;
import com.mlib.annotations.AnnotationHandler;
import com.mlib.gamemodifiers.ModConfigs;
import com.mlib.items.CreativeModeTabHelper;
import com.mlib.registries.RegistryHelper;
import net.minecraft.client.renderer.texture.TextureAtlas;
import com.mlib.triggers.BasicTrigger;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.CreativeModeTab;
Expand All @@ -28,15 +32,15 @@
import top.theillusivec4.curios.api.CuriosApi;
import top.theillusivec4.curios.api.SlotTypeMessage;

import java.util.List;

import static com.majruszsaccessories.MajruszsAccessories.SERVER_CONFIG;

public class Registries {
private static final RegistryHelper HELPER = new RegistryHelper( MajruszsAccessories.MOD_ID );

static {
ModConfigs.init( SERVER_CONFIG, Groups.DEFAULT );
ModConfigs.init( SERVER_CONFIG, Groups.ACCESSORIES ).name( "Accessories" );
ModConfigs.init( SERVER_CONFIG, Groups.BOOSTERS ).name( "Boosters" );
}

// Groups
Expand All @@ -47,8 +51,13 @@ public class Registries {
public static final RegistryObject< AccessoryItem > ADVENTURERS_GUIDE = ITEMS.register( "adventurers_guide", AccessoryItem::new );
public static final RegistryObject< AccessoryItem > ANGLERS_TROPHY = ITEMS.register( "anglers_trophy", AccessoryItem::new );
public static final RegistryObject< AccessoryItem > CERTIFICATE_OF_TAMING = ITEMS.register( "certificate_of_taming", AccessoryItem::new );
public static final RegistryObject< BoosterItem > DICE = ITEMS.register( "dice", BoosterItem.basic() );
public static final RegistryObject< BoosterItem > GOLDEN_DICE = ITEMS.register( "golden_dice", BoosterItem.rare() );
public static final RegistryObject< BoosterItem > GOLDEN_HORSESHOE = ITEMS.register( "golden_horseshoe", BoosterItem.rare() );
public static final RegistryObject< BoosterItem > HORSESHOE = ITEMS.register( "horseshoe", BoosterItem.basic() );
public static final RegistryObject< AccessoryItem > IDOL_OF_FERTILITY = ITEMS.register( "idol_of_fertility", AccessoryItem::new );
public static final RegistryObject< AccessoryItem > LUCKY_ROCK = ITEMS.register( "lucky_rock", AccessoryItem::new );
public static final RegistryObject< BoosterItem > OWL_FEATHER = ITEMS.register( "owl_feather", BoosterItem.basic() );
public static final RegistryObject< AccessoryItem > OVERWORLD_RUNE = ITEMS.register( "overworld_rune", AccessoryItem::new );
public static final RegistryObject< AccessoryItem > SECRET_INGREDIENT = ITEMS.register( "secret_ingredient", AccessoryItem::new );
public static final RegistryObject< AccessoryItem > TAMED_POTATO_BEETLE = ITEMS.register( "tamed_potato_beetle", AccessoryItem::new );
Expand All @@ -57,16 +66,16 @@ public class Registries {
// Recipes
public static final RegistryObject< RecipeSerializer< ? > > ACCESSORY_RECIPE = RECIPES.register( "crafting_accessory", AccessoryRecipe.create() );
public static final RegistryObject< RecipeSerializer< ? > > COMBINE_ACCESSORIES_RECIPE = RECIPES.register( "crafting_combine_accessories", CombineAccessoriesRecipe.create() );
public static final RegistryObject< RecipeSerializer< ? > > BOOST_ACCESSORIES_RECIPE = RECIPES.register( "crafting_boost_accessories", BoostAccessoriesRecipe.create() );

// Misc
public static final ResourceLocation ACCESSORY_SLOT_TEXTURE = Registries.getLocation( "item/empty_accessory_slot" );
public static final CreativeModeTab ITEM_GROUP = CreativeModeTabHelper.newTab( "majruszsaccessories.primary", LUCKY_ROCK );

// Game Modifiers
public static final List< Object > OBJECTS;
public static final RegistryObject< Item > BOOSTER_OVERLAY = ITEMS.register( "booster_icon", BoosterOverlay::new );
public static final BasicTrigger BASIC_TRIGGER = HELPER.registerBasicTrigger();

static {
OBJECTS = new AnnotationHandler( MajruszsAccessories.MOD_ID ).getInstances();
new AnnotationHandler( MajruszsAccessories.MOD_ID );
}

public static void initialize() {
Expand Down Expand Up @@ -109,5 +118,7 @@ private static void onTextureStitch( TextureStitchEvent.Pre event ) {

public static class Groups {
public static final String DEFAULT = Registries.getLocationString( "default" );
public static final String ACCESSORIES = Registries.getLocationString( "accessories" );
public static final String BOOSTERS = Registries.getLocationString( "boosters" );
}
}
Loading

0 comments on commit 9fa75e1

Please sign in to comment.