Make first working version (Time not work in Bad Air)
This commit is contained in:
@ -0,0 +1,35 @@
|
||||
package ru.bitheaven.createairfabric;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import fuzs.thinair.helper.AirHelper;
|
||||
import fuzs.thinair.helper.AirQualityLevel;
|
||||
import io.github.fabricators_of_create.porting_lib.util.EnvExecutor;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CreateAirFabric implements ModInitializer {
|
||||
public static final String ID = "createairfabric";
|
||||
public static final String NAME = "Create Air Fabric";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(NAME);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
LOGGER.info("Create addon mod [{}] is loading alongside Create [{}]!", NAME, Create.VERSION);
|
||||
LOGGER.info(EnvExecutor.unsafeRunForDist(
|
||||
() -> () -> "{} is accessing Porting Lib from the client!",
|
||||
() -> () -> "{} is accessing Porting Lib from the server!"
|
||||
), NAME);
|
||||
}
|
||||
|
||||
public static boolean airQualityActivatesHelmet(LivingEntity entity) {
|
||||
final var air = AirHelper.getO2LevelFromLocation(entity.getEyePosition(), entity.level()).getFirst();
|
||||
return air == AirQualityLevel.RED || air == AirQualityLevel.YELLOW;
|
||||
}
|
||||
|
||||
public static ResourceLocation id(String path) {
|
||||
return new ResourceLocation(ID, path);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package ru.bitheaven.createairfabric.mixin;
|
||||
|
||||
import fuzs.thinair.helper.AirHelper;
|
||||
import fuzs.thinair.helper.AirQualityLevel;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import ru.bitheaven.createairfabric.CreateAirFabric;
|
||||
import com.simibubi.create.content.equipment.armor.DivingHelmetItem;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
@Mixin(DivingHelmetItem.class)
|
||||
public abstract class DivingHelmetItemMixin {
|
||||
/**
|
||||
* Activate helmet "if in water or lava" -> "if in water or bad air or lava"
|
||||
*/
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"),
|
||||
method = "breatheUnderwater(Lnet/minecraft/world/entity/LivingEntity;)V")
|
||||
private static boolean redirectBreatheUnderwater(LivingEntity entity, TagKey<Fluid> fluidTagKey) {
|
||||
return entity.isEyeInFluid(fluidTagKey) || CreateAirFabric.airQualityActivatesHelmet(entity);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package ru.bitheaven.createairfabric.mixin;
|
||||
|
||||
import ru.bitheaven.createairfabric.CreateAirFabric;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import net.minecraft.client.main.GameConfig;
|
||||
|
||||
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 class MinecraftMixin {
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void example$init(GameConfig gameConfig, CallbackInfo ci) {
|
||||
CreateAirFabric.LOGGER.info("Hello from {}", CreateAirFabric.NAME);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user