Skip to content

Commit

Permalink
Merged 1.8.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed May 27, 2023
1 parent 43b0a7a commit 315d5b3
Show file tree
Hide file tree
Showing 33 changed files with 683 additions and 558 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [Modrinth](https://modrinth.com/mod/majruszs-enchantments)

## Current Mod Releases (Source Code)
- [v1.8.1 for Minecraft 1.19.3](https://github.com/Majrusz/MajruszsEnchantmentsMod/tree/1.19.X)
- [v1.8.2 for Minecraft 1.19.3](https://github.com/Majrusz/MajruszsEnchantmentsMod/tree/1.19.X)
- [v1.6.3 for Minecraft 1.18.2](https://github.com/Majrusz/MajruszsEnchantmentsMod/tree/1.18.X) *(not supported anymore)*
- [v1.5.2 for Minecraft 1.17.1](https://github.com/Majrusz/MajruszsEnchantmentsMod/tree/1.17.1) *(not supported anymore)*
- [v1.3.5 for Minecraft 1.16.5](https://github.com/Majrusz/MajruszsEnchantmentsMod/tree/1.16.4) *(not supported anymore)*
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'

version = '1.8.1'
version = '1.8.2'
group = 'com.majruszsenchantments'
archivesBaseName = 'majruszs-enchantments-1.19.2'

Expand Down Expand Up @@ -98,7 +98,7 @@ repositories {

dependencies {
minecraft 'net.minecraftforge:forge:1.19.2-43.2.0'
implementation fg.deobf( 'com.mlib:majrusz-library-1.19.2:3.2.0' )
implementation fg.deobf( 'com.mlib:majrusz-library-1.19.2:4.0.0' )
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}

Expand Down
Binary file removed libs/majrusz-library-1.19.2-3.2.0.jar
Binary file not shown.
Binary file added libs/majrusz-library-1.19.2-4.0.0.jar
Binary file not shown.
17 changes: 0 additions & 17 deletions src/main/java/com/majruszsenchantments/PacketHandler.java

This file was deleted.

38 changes: 10 additions & 28 deletions src/main/java/com/majruszsenchantments/Registries.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,36 @@

import com.majruszsenchantments.curses.*;
import com.majruszsenchantments.enchantments.*;
import com.majruszsenchantments.gamemodifiers.EnchantmentModifier;
import com.mlib.annotations.AnnotationHandler;
import com.mlib.gamemodifiers.GameModifier;
import com.mlib.gamemodifiers.ModConfigs;
import com.mlib.items.ItemHelper;
import com.mlib.registries.RegistryHelper;
import com.mlib.triggers.BasicTrigger;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.*;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.HorseArmorItem;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.List;
import java.util.function.Supplier;

import static com.majruszsenchantments.MajruszsEnchantments.CLIENT_CONFIG;
import static com.majruszsenchantments.MajruszsEnchantments.SERVER_CONFIG;

public class Registries {
private static final RegistryHelper HELPER = new RegistryHelper( MajruszsEnchantments.MOD_ID );
public static final List< GameModifier > GAME_MODIFIERS;

static {
GameModifier.addNewGroup( SERVER_CONFIG, Modifiers.ENCHANTMENT ).name( "Enchantments" );
GameModifier.addNewGroup( SERVER_CONFIG, Modifiers.CURSE ).name( "Curses" );
ModConfigs.init( SERVER_CONFIG, Groups.ENCHANTMENT ).name( "Enchantments" );
ModConfigs.init( SERVER_CONFIG, Groups.CURSE ).name( "Curses" );
}

// Groups
Expand Down Expand Up @@ -84,12 +80,11 @@ public class Registries {
public static final RegistryObject< SimpleParticleType > TELEKINESIS_PARTICLE = PARTICLE_TYPES.register( "telekinesis_particle", ()->new SimpleParticleType( true ) );

// Triggers
public static final BasicTrigger BASIC_TRIGGER = BasicTrigger.createRegisteredInstance( HELPER );
public static final BasicTrigger BASIC_TRIGGER = HELPER.registerBasicTrigger();

static {
// must stay below all instances because otherwise modifiers can access registry objects too fast
AnnotationHandler annotationHandler = new AnnotationHandler( MajruszsEnchantments.MOD_ID );
GAME_MODIFIERS = annotationHandler.getInstances( GameModifier.class );
new AnnotationHandler( MajruszsEnchantments.MOD_ID );
}

public static ResourceLocation getLocation( String register ) {
Expand All @@ -101,11 +96,7 @@ public static String getLocationString( String register ) {
}

public static void initialize() {
FMLJavaModLoadingContext modLoadingContext = FMLJavaModLoadingContext.get();
final IEventBus modEventBus = modLoadingContext.getModEventBus();

HELPER.registerAll();
modEventBus.addListener( PacketHandler::registerPacket );
DistExecutor.unsafeRunWhenOn( Dist.CLIENT, ()->RegistriesClient::initialize );
ItemHelper.addEnchantmentTypesToItemGroup( CreativeModeTab.TAB_COMBAT, SHIELD, BOW_AND_CROSSBOW, MELEE_MINECRAFT, MELEE );
ItemHelper.addEnchantmentTypesToItemGroup( CreativeModeTab.TAB_TOOLS, HOE, GOLDEN, TOOLS );
Expand All @@ -115,16 +106,7 @@ public static void initialize() {
CLIENT_CONFIG.register( ModLoadingContext.get() );
}

public static < Type extends EnchantmentModifier< ? > > Supplier< Boolean > getEnabledSupplier( Class< Type > clazz ) {
var enchantmentModifier = GAME_MODIFIERS.stream()
.filter( modifier->clazz.equals( modifier.getClass() ) )
.findFirst()
.orElseThrow();

return clazz.cast( enchantmentModifier ).getEnabledSupplier();
}

public static class Modifiers {
public static class Groups {
public static final String ENCHANTMENT = Registries.getLocationString( "enchantment" );
public static final String CURSE = Registries.getLocationString( "curse" );
}
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/com/majruszsenchantments/curses/BreakingCurse.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.majruszsenchantments.curses;

import com.majruszsenchantments.Registries;
import com.majruszsenchantments.gamemodifiers.EnchantmentModifier;
import com.mlib.EquipmentSlots;
import com.mlib.Random;
import com.mlib.annotations.AutoInstance;
import com.mlib.config.ConfigGroup;
import com.mlib.config.DoubleConfig;
import com.mlib.enchantments.CustomEnchantment;
import com.mlib.gamemodifiers.Condition;
import com.mlib.gamemodifiers.ModConfigs;
import com.mlib.gamemodifiers.contexts.OnEnchantmentAvailabilityCheck;
import com.mlib.gamemodifiers.contexts.OnItemHurt;
import com.mlib.math.Range;
import net.minecraft.world.item.enchantment.DigDurabilityEnchantment;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;

import java.util.function.Supplier;

public class BreakingCurse extends CustomEnchantment {
public BreakingCurse() {
this.rarity( Rarity.RARE )
Expand All @@ -22,8 +26,7 @@ public BreakingCurse() {
.curse()
.maxLevel( 3 )
.minLevelCost( level->10 )
.maxLevelCost( level->50 )
.setEnabledSupplier( Registries.getEnabledSupplier( Modifier.class ) );
.maxLevelCost( level->50 );
}

@Override
Expand All @@ -32,25 +35,30 @@ public boolean checkCompatibility( Enchantment enchantment ) {
}

@AutoInstance
public static class Modifier extends EnchantmentModifier< BreakingCurse > {
public static class Handler {
final DoubleConfig damageMultiplier = new DoubleConfig( 1.0, new Range<>( 0.0, 10.0 ) );
final Supplier< BreakingCurse > enchantment = Registries.BREAKING;

public Modifier() {
super( Registries.BREAKING, Registries.Modifiers.CURSE );
public Handler() {
ConfigGroup group = ModConfigs.registerSubgroup( Registries.Groups.CURSE )
.name( "Breaking" )
.comment( "Makes all items break faster." );

new OnItemHurt.Context( this::dealExtraDamage )
.addCondition( data->data.player != null )
.addCondition( new Condition.HasEnchantment<>( this.enchantment ) )
.addConfig( this.damageMultiplier.name( "damage_multiplier" ).comment( "Extra damage multiplier per enchantment level." ) )
.insertTo( this );
OnEnchantmentAvailabilityCheck.listen( OnEnchantmentAvailabilityCheck.ENABLE )
.addCondition( OnEnchantmentAvailabilityCheck.is( this.enchantment ) )
.addCondition( OnEnchantmentAvailabilityCheck.excludable() )
.insertTo( group );

this.name( "Breaking" ).comment( "Makes all items break faster." );
OnItemHurt.listen( this::dealExtraDamage )
.addCondition( Condition.hasEnchantment( this.enchantment, data->data.player ) )
.addConfig( this.damageMultiplier.name( "damage_multiplier" ).comment( "Extra damage multiplier per enchantment level." ) )
.insertTo( group );
}

private void dealExtraDamage( OnItemHurt.Data data ) {
assert data.player != null;
double damageMultiplier = this.enchantment.get().getEnchantmentLevel( data.itemStack ) * this.damageMultiplier.get();
data.event.extraDamage += Random.roundRandomly( data.event.damage * damageMultiplier );
data.extraDamage += Random.roundRandomly( data.damage * damageMultiplier );
}
}
}
37 changes: 23 additions & 14 deletions src/main/java/com/majruszsenchantments/curses/CorrosionCurse.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.majruszsenchantments.curses;

import com.majruszsenchantments.Registries;
import com.majruszsenchantments.gamemodifiers.EnchantmentModifier;
import com.mlib.EquipmentSlots;
import com.mlib.annotations.AutoInstance;
import com.mlib.config.ConfigGroup;
import com.mlib.config.DoubleConfig;
import com.mlib.enchantments.CustomEnchantment;
import com.mlib.gamemodifiers.Condition;
import com.mlib.gamemodifiers.ModConfigs;
import com.mlib.gamemodifiers.contexts.OnEnchantmentAvailabilityCheck;
import com.mlib.gamemodifiers.contexts.OnEntityTick;
import com.mlib.levels.LevelHelper;
import com.mlib.math.Range;
Expand All @@ -17,33 +19,40 @@
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraftforge.api.distmarker.Dist;

import java.util.function.Supplier;

public class CorrosionCurse extends CustomEnchantment {
public CorrosionCurse() {
this.rarity( Rarity.RARE )
.category( EnchantmentCategory.ARMOR )
.slots( EquipmentSlots.ARMOR )
.curse()
.minLevelCost( level->10 )
.maxLevelCost( level->50 )
.setEnabledSupplier( Registries.getEnabledSupplier( Modifier.class ) );
.maxLevelCost( level->50 );
}

@AutoInstance
public static class Modifier extends EnchantmentModifier< CorrosionCurse > {
public static class Handler {
final DoubleConfig damageAmount = new DoubleConfig( 0.25, new Range<>( 0.0, 10.0 ) );
final Supplier< CorrosionCurse > enchantment = Registries.CORROSION;

public Modifier() {
super( Registries.CORROSION, Registries.Modifiers.CURSE );
public Handler() {
ConfigGroup group = ModConfigs.registerSubgroup( Registries.Groups.CURSE )
.name( "Corrosion" )
.comment( "Gradually destroys the item and inflicts damage to the owner when in water." );

new OnEntityTick.Context( this::damageOnContactWithWater )
.addCondition( new Condition.IsServer<>() )
.addCondition( new Condition.HasEnchantment<>( this.enchantment ) )
.addCondition( new Condition.Cooldown<>( 3.0, Dist.DEDICATED_SERVER ) )
.addCondition( data->LevelHelper.isEntityOutsideWhenItIsRaining( data.entity ) || data.entity.isInWater() )
.addConfig( this.damageAmount.name( "damage_amount" ).comment( "Damage dealt to the player every tick per each enchantment level." ) )
.insertTo( this );
OnEnchantmentAvailabilityCheck.listen( OnEnchantmentAvailabilityCheck.ENABLE )
.addCondition( OnEnchantmentAvailabilityCheck.is( this.enchantment ) )
.addCondition( OnEnchantmentAvailabilityCheck.excludable() )
.insertTo( group );

this.name( "Corrosion" ).comment( "Gradually destroys the item and inflicts damage to the owner when in water." );
OnEntityTick.listen( this::damageOnContactWithWater )
.addCondition( Condition.isServer() )
.addCondition( Condition.hasEnchantment( this.enchantment, data->data.entity ) )
.addCondition( Condition.cooldown( 3.0, Dist.DEDICATED_SERVER ) )
.addCondition( Condition.predicate( data->LevelHelper.isRainingAt( data.entity ) || data.entity.isInWater() ) )
.addConfig( this.damageAmount.name( "damage_amount" ).comment( "Damage dealt to the player every tick per each enchantment level." ) )
.insertTo( group );
}

private void damageOnContactWithWater( OnEntityTick.Data data ) {
Expand Down
Loading

0 comments on commit 315d5b3

Please sign in to comment.