-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
188 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
- changed mod id from `mlib` to `majruszlibrary` (suggested by @ChiefArug) | ||
- optimized and reworked multiple features | ||
- fixed game crash `java.lang.NullPointerException: Registry Object not present` | ||
- fixed game crash `java.lang.NullPointerException: Registry Object not present` (reported by @reboundrefice) | ||
- fixed bug with trying to load folders instead of mods (reported by @SettingDust) | ||
- fixed bug with weather changes not working properly | ||
- fixed compatibility issue with Sodium (reported by @LonelyFear) | ||
- fixed compatibility issue with Epic Fight (reported by @Orphion_) | ||
- fixed compatibility issue with Marium's Soulslike Weaponry (reported by @mariumbacchus) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
common/src/main/java/com/majruszlibrary/events/OnItemRenderColorsGet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.majruszlibrary.events; | ||
|
||
import com.majruszlibrary.annotation.Dist; | ||
import com.majruszlibrary.annotation.OnlyIn; | ||
import com.majruszlibrary.events.base.Event; | ||
import com.majruszlibrary.events.base.Events; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
public class OnItemRenderColorsGet { | ||
public final ItemStack itemStack; | ||
private final Map< Integer, Integer > colors = new HashMap<>(); | ||
|
||
public static Event< OnItemRenderColorsGet > listen( Consumer< OnItemRenderColorsGet > consumer ) { | ||
return Events.get( OnItemRenderColorsGet.class ).add( consumer ); | ||
} | ||
|
||
public OnItemRenderColorsGet( ItemStack itemStack ) { | ||
this.itemStack = itemStack; | ||
} | ||
|
||
public void add( int layerIdx, int color ) { | ||
this.colors.put( layerIdx, color ); | ||
} | ||
|
||
public boolean hasColorsDefined() { | ||
return this.colors.size() > 0; | ||
} | ||
|
||
@OnlyIn( Dist.CLIENT ) | ||
public ItemColor toItemColor() { | ||
return new ItemColor( this.colors ); | ||
} | ||
|
||
@OnlyIn( Dist.CLIENT ) | ||
public static class ItemColor implements net.minecraft.client.color.item.ItemColor { | ||
private final Map< Integer, Integer > colors; | ||
|
||
public ItemColor( Map< Integer, Integer > colors ) { | ||
this.colors = colors; | ||
} | ||
|
||
@Override | ||
public int getColor( ItemStack itemStack, int layerIdx ) { | ||
return this.colors.getOrDefault( layerIdx, 0xffffff ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 23 additions & 3 deletions
26
common/src/main/java/com/majruszlibrary/mixin/MixinItemColors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,42 @@ | ||
package com.majruszlibrary.mixin; | ||
|
||
import com.majruszlibrary.events.OnItemRenderColorGet; | ||
import com.majruszlibrary.events.OnItemRenderColorsGet; | ||
import com.majruszlibrary.events.base.Events; | ||
import net.minecraft.client.color.item.ItemColor; | ||
import net.minecraft.client.color.item.ItemColors; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Dynamic; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin( ItemColors.class ) | ||
@Mixin( value = ItemColors.class, priority = 1100 ) | ||
public abstract class MixinItemColors { | ||
@Inject( | ||
at = @At( "RETURN" ), | ||
cancellable = true, | ||
method = "getColor (Lnet/minecraft/world/item/ItemStack;I)I" | ||
) | ||
private void getColor( ItemStack itemStack, int layerIdx, CallbackInfoReturnable< Integer > callback ) { | ||
callback.setReturnValue( Events.dispatch( new OnItemRenderColorGet( itemStack, layerIdx, callback.getReturnValue() ) ).getColor() ); | ||
OnItemRenderColorsGet data = Events.dispatch( new OnItemRenderColorsGet( itemStack ) ); | ||
if( data.hasColorsDefined() ) { | ||
callback.setReturnValue( data.toItemColor().getColor( itemStack, layerIdx ) ); | ||
} | ||
} | ||
|
||
@Dynamic( "Sodium compatibility" ) | ||
@Inject( | ||
at = @At( "RETURN" ), | ||
cancellable = true, | ||
method = "sodium$getColorProvider", | ||
remap = false, | ||
require = 0 | ||
) | ||
private void getColorProvider( ItemStack itemStack, CallbackInfoReturnable< ItemColor > callback ) { | ||
OnItemRenderColorsGet data = Events.dispatch( new OnItemRenderColorsGet( itemStack ) ); | ||
if( data.hasColorsDefined() ) { | ||
callback.setReturnValue( data.toItemColor() ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 35 additions & 32 deletions
67
fabric/src/main/java/com/majruszlibrary/mixin/fabric/MixinEnchantmentHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,59 @@ | ||
package com.majruszlibrary.mixin.fabric; | ||
|
||
import com.majruszlibrary.item.CustomEnchantment; | ||
import net.minecraft.world.item.Item; | ||
import com.majruszlibrary.registry.Registries; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
import net.minecraft.world.item.enchantment.EnchantmentCategory; | ||
import net.minecraft.world.item.enchantment.EnchantmentHelper; | ||
import net.minecraft.world.item.enchantment.EnchantmentInstance; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.List; | ||
|
||
@Mixin( EnchantmentHelper.class ) | ||
public abstract class MixinEnchantmentHelper { | ||
private static ItemStack majruszlibrary$LAST_ITEM_STACK = null; | ||
private static Enchantment majruszlibrary$LAST_ENCHANTMENT = null; | ||
|
||
@ModifyVariable( | ||
at = @At( "STORE" ), | ||
method = "getAvailableEnchantmentResults (ILnet/minecraft/world/item/ItemStack;Z)Ljava/util/List;" | ||
) | ||
private static Enchantment getEnchantment( Enchantment enchantment ) { | ||
majruszlibrary$LAST_ENCHANTMENT = enchantment; | ||
|
||
return enchantment; | ||
} | ||
|
||
// TODO: in Fabric 0.15.0+ there will be a native support for MixinExtras that can be used to make it cleaner | ||
@Inject( | ||
at = @At( "HEAD" ), | ||
at = @At( "RETURN" ), | ||
cancellable = true, | ||
method = "getAvailableEnchantmentResults (ILnet/minecraft/world/item/ItemStack;Z)Ljava/util/List;" | ||
) | ||
private static void getAvailableEnchantmentResults( int $$0, ItemStack itemStack, boolean $$2, | ||
private static void getAvailableEnchantmentResults( int level, ItemStack itemStack, boolean isTreasure, | ||
CallbackInfoReturnable< List< EnchantmentInstance > > callback | ||
) { | ||
majruszlibrary$LAST_ITEM_STACK = itemStack; | ||
} | ||
List< EnchantmentInstance > enchantments = callback.getReturnValue(); | ||
enchantments.removeIf( enchantment->enchantment.enchantment instanceof CustomEnchantment ); | ||
boolean isBook = itemStack.is( Items.BOOK ); | ||
|
||
@Redirect( | ||
at = @At( | ||
target = "Lnet/minecraft/world/item/enchantment/EnchantmentCategory;canEnchant (Lnet/minecraft/world/item/Item;)Z", | ||
value = "INVOKE" | ||
), | ||
method = "getAvailableEnchantmentResults (ILnet/minecraft/world/item/ItemStack;Z)Ljava/util/List;" | ||
) | ||
private static boolean canEnchantUsingEnchantingTable( EnchantmentCategory category, Item item ) { | ||
return majruszlibrary$LAST_ENCHANTMENT instanceof CustomEnchantment enchantment | ||
? enchantment.canEnchantUsingEnchantingTable( majruszlibrary$LAST_ITEM_STACK ) | ||
: category.canEnchant( item ); | ||
for( Enchantment enchantment : Registries.ENCHANTMENTS ) { | ||
if( !( enchantment instanceof CustomEnchantment customEnchantment ) ) { | ||
continue; | ||
} | ||
|
||
if( enchantment.isTreasureOnly() && !isTreasure ) { | ||
continue; | ||
} | ||
|
||
if( !enchantment.isDiscoverable() ) { | ||
continue; | ||
} | ||
|
||
if( !customEnchantment.canEnchantUsingEnchantingTable( itemStack ) && !isBook ) { | ||
continue; | ||
} | ||
|
||
for( int enchantmentLevel = enchantment.getMaxLevel(); enchantmentLevel > enchantment.getMinLevel() - 1; --enchantmentLevel ) { | ||
if( level >= enchantment.getMinCost( enchantmentLevel ) && level <= enchantment.getMaxCost( enchantmentLevel ) ) { | ||
enchantments.add( new EnchantmentInstance( enchantment, enchantmentLevel ) ); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
callback.setReturnValue( enchantments ); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
fabric/src/main/java/com/majruszlibrary/mixin/fabric/MixinMinecraft.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.majruszlibrary.mixin.fabric; | ||
|
||
import com.majruszlibrary.events.OnGameInitialized; | ||
import com.majruszlibrary.events.base.Events; | ||
import net.minecraft.client.Minecraft; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin( Minecraft.class ) | ||
public abstract class MixinMinecraft { | ||
@Inject( | ||
at = @At( "HEAD" ), | ||
method = "onGameLoadFinished ()V" | ||
) | ||
private void onGameLoadFinished( CallbackInfo callback ) { | ||
Events.dispatch( new OnGameInitialized() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
forge/src/main/java/com/majruszlibrary/events/OnGameInitializedForge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.majruszlibrary.events; | ||
|
||
import com.majruszlibrary.events.base.Events; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; | ||
|
||
@Mod.EventBusSubscriber( value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD ) | ||
public class OnGameInitializedForge { | ||
@SubscribeEvent | ||
public static void initialize( FMLClientSetupEvent event ) { | ||
event.enqueueWork( ()->Events.dispatch( new OnGameInitialized() ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
neoforge/src/main/java/com/majruszlibrary/events/OnGameInitializedNeoForge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.majruszlibrary.events; | ||
|
||
import com.majruszlibrary.events.base.Events; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; | ||
|
||
@Mod.EventBusSubscriber( value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD ) | ||
public class OnGameInitializedNeoForge { | ||
@SubscribeEvent | ||
public static void initialize( FMLClientSetupEvent event ) { | ||
event.enqueueWork( ()->Events.dispatch( new OnGameInitialized() ) ); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
neoforge/src/main/resources/META-INF/services/com.majruszlibrary.modhelper.IDataPlatform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.majruszlibrary.modhelper.DataNeoForge |