|
| 1 | +package org.sinytra.ffapi.mixin.fluids; |
| 2 | + |
| 3 | +import net.minecraft.core.Holder; |
| 4 | +import net.minecraft.core.HolderSet; |
| 5 | +import net.minecraft.core.registries.BuiltInRegistries; |
| 6 | +import net.minecraft.tags.TagKey; |
| 7 | +import net.minecraft.world.entity.EntityFluidInteraction; |
| 8 | + |
| 9 | +import net.neoforged.neoforge.fluids.FluidType; |
| 10 | +import org.sinytra.ffapi.impl.fluids.FabricFluidTypes; |
| 11 | +import org.spongepowered.asm.mixin.Mixin; |
| 12 | +import org.spongepowered.asm.mixin.injection.At; |
| 13 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 14 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 15 | + |
| 16 | +import net.minecraft.world.level.material.Fluid; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | +import java.util.Optional; |
| 20 | + |
| 21 | +@Mixin(EntityFluidInteraction.class) |
| 22 | +public class EntityFluidInteractionMixin { |
| 23 | + @Inject(method = "getFluidTypeByTag", at = @At(value = "INVOKE", target = "Ljava/lang/IllegalArgumentException;<init>(Ljava/lang/String;)V"), cancellable = true) |
| 24 | + private static void getFabricVanillaFluidType(TagKey<Fluid> fluidTag, CallbackInfoReturnable<FluidType> cir) { |
| 25 | + BuiltInRegistries.FLUID.get(fluidTag).ifPresent(named->{ |
| 26 | + List<Holder<Fluid>> contents = named.contents(); |
| 27 | + if (contents.isEmpty()) return; |
| 28 | + FluidType fabricFluidType = FabricFluidTypes.getFluidType(contents.getFirst().value()); |
| 29 | + if (fabricFluidType != null) { |
| 30 | + cir.setReturnValue(fabricFluidType); |
| 31 | + } |
| 32 | + }); |
| 33 | + } |
| 34 | +} |
0 commit comments