First push
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package ru.bitheaven.createastrafabric;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import earth.terrarium.ad_astra.common.util.OxygenUtils;
|
||||
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 net.minecraft.world.level.Level;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CreateAstraFabric implements ModInitializer {
|
||||
public static final String ID = "createastrafabric";
|
||||
public static final String NAME = "Create Astra 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 Level level = entity.level();
|
||||
final boolean air = OxygenUtils.levelHasOxygen(level);
|
||||
return !air || entity.isUnderWater();
|
||||
}
|
||||
|
||||
public static ResourceLocation id(String path) {
|
||||
return new ResourceLocation(ID, path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.bitheaven.createastrafabric.mixin;
|
||||
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
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.createastrafabric.CreateAstraFabric;
|
||||
import com.simibubi.create.content.equipment.armor.DivingHelmetItem;
|
||||
|
||||
@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) || CreateAstraFabric.airQualityActivatesHelmet(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package ru.bitheaven.createastrafabric.mixin;
|
||||
|
||||
import com.simibubi.create.content.equipment.armor.BacktankUtil;
|
||||
import com.simibubi.create.content.equipment.armor.DivingHelmetItem;
|
||||
import earth.terrarium.ad_astra.common.entity.system.EntityOxygenSystem;
|
||||
import earth.terrarium.ad_astra.common.util.ModUtils;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(EntityOxygenSystem.class)
|
||||
public abstract class EntityOxygenSystemMixin {
|
||||
/**
|
||||
* Make air exists if Create Air
|
||||
*/
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Learth/terrarium/ad_astra/common/util/ModUtils;armourIsOxygenated(Lnet/minecraft/world/entity/LivingEntity;)Z"),
|
||||
method = "oxygenTick(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/server/level/ServerLevel;)V")
|
||||
private static boolean redirectOxygenTick(LivingEntity entity) {
|
||||
boolean createOxygen = true;
|
||||
createOxygen &= !DivingHelmetItem.getWornItem(entity).isEmpty();
|
||||
createOxygen &= !BacktankUtil.getAllWithAir(entity).isEmpty();
|
||||
return ModUtils.armourIsOxygenated(entity) || createOxygen;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ru.bitheaven.createastrafabric.mixin;
|
||||
|
||||
import ru.bitheaven.createastrafabric.CreateAstraFabric;
|
||||
|
||||
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) {
|
||||
CreateAstraFabric.LOGGER.info("Hello from {}", CreateAstraFabric.NAME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package ru.bitheaven.createastrafabric.mixin;
|
||||
|
||||
|
||||
import com.simibubi.create.content.equipment.armor.RemainingAirOverlay;
|
||||
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.createastrafabric.CreateAstraFabric;
|
||||
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
|
||||
@Mixin(RemainingAirOverlay.class)
|
||||
public class RemainingAirOverlayMixin {
|
||||
/**
|
||||
* Activate UI "if in water or lava" -> "if in water or bad air or lava"
|
||||
*/
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"),
|
||||
method = "render(Lnet/minecraft/client/gui/GuiGraphics;II)V")
|
||||
private static boolean redirectRender(LocalPlayer player, TagKey<Fluid> fluidTagKey) {
|
||||
return player.isEyeInFluid(fluidTagKey) || CreateAstraFabric.airQualityActivatesHelmet(player);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user