Skip to content

Commit

Permalink
Fix compatibility between BetterNether and Apotheosis
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Mar 27, 2024
1 parent a26ac1c commit c4ee605
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Optional;

@Mod(ConnectorUtil.CONNECTOR_MODID)
public class ConnectorMod {
public static final Logger LOG = LoggerFactory.getLogger(ConnectorMod.class);

private static boolean clientLoadComplete;
private static boolean preventFreeze;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package dev.su5ed.sinytra.connector.mod.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import dev.su5ed.sinytra.connector.ConnectorUtil;
import dev.su5ed.sinytra.connector.mod.ConnectorMod;
import dev.su5ed.sinytra.connector.mod.compat.FluidHandlerCompat;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.DefaultAttributes;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fluids.FluidType;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Map;

@Mixin(ForgeHooks.class)
public abstract class ForgeHooksMixin {

Expand All @@ -19,4 +29,18 @@ private static void getFabricVanillaFluidType(Fluid fluid, CallbackInfoReturnabl
cir.setReturnValue(fabricFluidType);
}
}

@Inject(at = @At("TAIL"), method = "modifyAttributes", remap = false)
private static void connector$allowAttributeMixins(CallbackInfo ci, @Local Map<EntityType<? extends LivingEntity>, AttributeSupplier.Builder> modifiedMap) {
modifiedMap.forEach((entity, attributes) -> {
final var fromVanilla = DefaultAttributes.getSupplier(entity);
// A mod is mixing into DefaultAttributes to add their attribute
if (ForgeHooks.getAttributesView().get(entity) != fromVanilla) {
ConnectorMod.LOG.debug("Entity {} has its attributes added via a mixin. Adding event-modified attributes.", entity);
final AttributeSupplier.Builder newBuilder = new AttributeSupplier.Builder(fromVanilla);
newBuilder.combine(attributes);
fromVanilla.instances = newBuilder.build().instances;
}
});
}
}

0 comments on commit c4ee605

Please sign in to comment.