mirror of
https://github.com/XevianLight/Aphelion.git
synced 2026-05-11 01:50:56 +01:00
Added oxygen damage and an oxygen damage source
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
package net.xevianlight.aphelion.core.init;
|
||||||
|
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
|
import net.minecraft.world.damagesource.DamageType;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.xevianlight.aphelion.Aphelion;
|
||||||
|
|
||||||
|
public class ModDamageSources {
|
||||||
|
|
||||||
|
// Relatively sure this is right
|
||||||
|
public static final ResourceKey<DamageType> OXYGEN = ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "oxygen"));
|
||||||
|
|
||||||
|
public static DamageSource create(Level level, ResourceKey<DamageType> key) {
|
||||||
|
return new DamageSource(level.registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package net.xevianlight.aphelion.mixins.common;
|
||||||
|
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.xevianlight.aphelion.systems.OxygenService;
|
||||||
|
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(LivingEntity.class)
|
||||||
|
public abstract class LivingEntityMixin extends Entity {
|
||||||
|
|
||||||
|
public LivingEntityMixin(EntityType<?> type, Level level) { super(type, level); }
|
||||||
|
|
||||||
|
@Inject(method= "tick", at = @At("TAIL"))
|
||||||
|
public void aphelion$tick(CallbackInfo ci) {
|
||||||
|
if ((level() instanceof ServerLevel level)) {
|
||||||
|
LivingEntity entity = (LivingEntity) (Object) this;
|
||||||
|
|
||||||
|
// Oxygen system
|
||||||
|
OxygenService.entityTick(level, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package net.xevianlight.aphelion.systems;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.xevianlight.aphelion.Aphelion;
|
||||||
|
import net.xevianlight.aphelion.core.init.ModDamageSources;
|
||||||
|
import net.xevianlight.aphelion.core.saveddata.EnvironmentSavedData;
|
||||||
|
|
||||||
|
public class OxygenService {
|
||||||
|
public static boolean hasOxygen(Level level, BlockPos pos) {
|
||||||
|
if (level.isClientSide) {
|
||||||
|
// We can't pull oxygen data from the client side, so just, uhh, don't!
|
||||||
|
Aphelion.LOGGER.warn("Tried to get server oxygen data from client side!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean positionHasOxygen = EnvironmentSavedData.get((ServerLevel) level).hasOxygen(level, pos);
|
||||||
|
|
||||||
|
return positionHasOxygen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasOxygen(Entity entity) {
|
||||||
|
// Not sure if this is at the entity's feet, head, or the middle... research later
|
||||||
|
BlockPos entityBlockPos = BlockPos.containing(entity.getX(), entity.getY(), entity.getZ());
|
||||||
|
return hasOxygen(entity.level(), entityBlockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int OXYGEN_DAMAGE_TICK_AMT = 2;
|
||||||
|
public static int OXYGEN_DAMAGE_TICK_FREQ = 20;
|
||||||
|
/// Called by LivingEntity.entityTick mixin
|
||||||
|
public static void entityTick(ServerLevel level, LivingEntity entity) {
|
||||||
|
if (entity.tickCount % OXYGEN_DAMAGE_TICK_FREQ != 0) return;
|
||||||
|
if (hasOxygen(entity)) return;
|
||||||
|
entity.hurt(ModDamageSources.create(level, ModDamageSources.OXYGEN), OXYGEN_DAMAGE_TICK_AMT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
"package": "net.xevianlight.aphelion.mixins",
|
"package": "net.xevianlight.aphelion.mixins",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"common.LivingEntityMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"common.ClientLevelMixin",
|
"common.ClientLevelMixin",
|
||||||
|
|||||||
7
src/main/resources/data/aphelion/damage_type/oxygen.json
Normal file
7
src/main/resources/data/aphelion/damage_type/oxygen.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"message_id": "%1$s remembers' your §bOxygens",
|
||||||
|
"scaling": "never",
|
||||||
|
"exhaustion": 0,
|
||||||
|
"effects": "drowning",
|
||||||
|
"death_message_type": "default"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
"aphelion:oxygen"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user