diff --git a/src/main/java/com/thebrokenrail/energonrelics/EnergonRelics.java b/src/main/java/com/thebrokenrail/energonrelics/EnergonRelics.java index 21e5f02..9b64cc5 100644 --- a/src/main/java/com/thebrokenrail/energonrelics/EnergonRelics.java +++ b/src/main/java/com/thebrokenrail/energonrelics/EnergonRelics.java @@ -17,6 +17,7 @@ import com.thebrokenrail.energonrelics.block.SwitchBlock; import com.thebrokenrail.energonrelics.block.util.SimpleBlock; import com.thebrokenrail.energonrelics.item.MultimeterItem; import com.thebrokenrail.energonrelics.item.NetworkChipItem; +import com.thebrokenrail.energonrelics.potion.CustomPotions; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -104,5 +105,7 @@ public class EnergonRelics implements ModInitializer { BLOCK_BREAKER_BLOCK.register("block_breaker"); Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "veridium_powder"), VERIDIUM_POWDER_ITEM); + + CustomPotions.register(); } } diff --git a/src/main/java/com/thebrokenrail/energonrelics/mixin/BrewingRecipeRegistryAccessor.java b/src/main/java/com/thebrokenrail/energonrelics/mixin/BrewingRecipeRegistryAccessor.java new file mode 100644 index 0000000..ed6e2be --- /dev/null +++ b/src/main/java/com/thebrokenrail/energonrelics/mixin/BrewingRecipeRegistryAccessor.java @@ -0,0 +1,15 @@ +package com.thebrokenrail.energonrelics.mixin; + +import net.minecraft.item.Item; +import net.minecraft.potion.Potion; +import net.minecraft.recipe.BrewingRecipeRegistry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(BrewingRecipeRegistry.class) +public interface BrewingRecipeRegistryAccessor { + @Invoker + static void callRegisterPotionRecipe(Potion input, Item item, Potion output) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/com/thebrokenrail/energonrelics/mixin/MixinLivingEntity.java b/src/main/java/com/thebrokenrail/energonrelics/mixin/MixinLivingEntity.java new file mode 100644 index 0000000..764d073 --- /dev/null +++ b/src/main/java/com/thebrokenrail/energonrelics/mixin/MixinLivingEntity.java @@ -0,0 +1,61 @@ +package com.thebrokenrail.energonrelics.mixin; + +import com.thebrokenrail.energonrelics.potion.CustomPotions; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.attribute.EntityAttribute; +import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.data.DataTracker; +import net.minecraft.entity.data.TrackedData; +import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.effect.StatusEffect; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +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; + +@Mixin(LivingEntity.class) +public abstract class MixinLivingEntity { + @Unique + private static final TrackedData HAS_VERIDIUM_POISONING = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.BOOLEAN); + + @Shadow + public abstract boolean hasStatusEffect(StatusEffect effect); + + @Shadow + public abstract void setHealth(float health); + + @Shadow + public abstract float getHealth(); + + @Inject(at = @At("RETURN"), method = "initDataTracker") + public void initDataTracker(CallbackInfo info) { + ((LivingEntity) (Object) this).getDataTracker().startTracking(HAS_VERIDIUM_POISONING, false); + } + + @Inject(at = @At("RETURN"), method = "onTrackedDataSet") + public void onTrackedDataSet(TrackedData data, CallbackInfo info) { + if (HAS_VERIDIUM_POISONING.equals(data)) { + setHealth(getHealth()); + } + } + + @Inject(at = @At("HEAD"), method = "tick") + public void tick(CallbackInfo info) { + if (!((LivingEntity) (Object) this).getEntityWorld().isClient()) { + boolean hasVeridiumPoisoning = hasStatusEffect(CustomPotions.VERIDIUM_POISONING_EFFECT.statusEffect); + if (((LivingEntity) (Object) this).getDataTracker().get(HAS_VERIDIUM_POISONING) != hasVeridiumPoisoning) { + ((LivingEntity) (Object) this).getDataTracker().set(HAS_VERIDIUM_POISONING, hasVeridiumPoisoning); + } + } + } + + @Inject(at = @At("HEAD"), method = "getAttributeValue", cancellable = true) + public void getAttributeValue(EntityAttribute attribute, CallbackInfoReturnable info) { + if (EntityAttributes.GENERIC_MAX_HEALTH.equals(attribute) && ((LivingEntity) (Object) this).getDataTracker().get(HAS_VERIDIUM_POISONING)) { + info.setReturnValue(0.5d); + } + } +} diff --git a/src/main/java/com/thebrokenrail/energonrelics/potion/CustomPotions.java b/src/main/java/com/thebrokenrail/energonrelics/potion/CustomPotions.java new file mode 100644 index 0000000..427aa35 --- /dev/null +++ b/src/main/java/com/thebrokenrail/energonrelics/potion/CustomPotions.java @@ -0,0 +1,53 @@ +package com.thebrokenrail.energonrelics.potion; + +import com.thebrokenrail.energonrelics.EnergonRelics; +import com.thebrokenrail.energonrelics.mixin.BrewingRecipeRegistryAccessor; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffectType; +import net.minecraft.item.Items; +import net.minecraft.potion.Potion; +import net.minecraft.potion.Potions; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; + +public class CustomPotions { + public static class CustomPotion { + private static class CustomStatusEffect extends StatusEffect { + private CustomStatusEffect(StatusEffectType type, int color) { + super(type, color); + } + } + + public final StatusEffect statusEffect; + private final Potion potion; + private final Potion longPotion; + + private CustomPotion(StatusEffect statusEffect, Potion potion, Potion longPotion) { + this.statusEffect = statusEffect; + this.potion = potion; + this.longPotion = longPotion; + } + } + + public static CustomPotion VERIDIUM_POISONING_EFFECT; + + public static void register() { + VERIDIUM_POISONING_EFFECT = registerEffect("veridium_poisoning", 16711909); + registerBrewingRecipes(); + } + + @SuppressWarnings("SameParameterValue") + private static CustomPotion registerEffect(String name, int color) { + StatusEffect effect = Registry.register(Registry.STATUS_EFFECT, new Identifier(EnergonRelics.NAMESPACE, name), new CustomPotion.CustomStatusEffect(StatusEffectType.HARMFUL, color)); + Potion potion = Registry.register(Registry.POTION, new Identifier(EnergonRelics.NAMESPACE, name), new Potion(EnergonRelics.NAMESPACE + '.' + name, new StatusEffectInstance(effect, 1800))); + Potion longPotion = Registry.register(Registry.POTION, new Identifier(EnergonRelics.NAMESPACE, "long_" + name), new Potion(EnergonRelics.NAMESPACE + '.' + name, new StatusEffectInstance(effect, 4800))); + return new CustomPotion(effect, potion, longPotion); + } + + private static void registerBrewingRecipes() { + BrewingRecipeRegistryAccessor.callRegisterPotionRecipe(Potions.AWKWARD, EnergonRelics.VERIDIUM_POWDER_ITEM, VERIDIUM_POISONING_EFFECT.potion); + BrewingRecipeRegistryAccessor.callRegisterPotionRecipe(VERIDIUM_POISONING_EFFECT.potion, Items.REDSTONE, VERIDIUM_POISONING_EFFECT.longPotion); + } + +} diff --git a/src/main/resources/assets/energonrelics/lang/en_us.json b/src/main/resources/assets/energonrelics/lang/en_us.json index 8527f62..a760265 100644 --- a/src/main/resources/assets/energonrelics/lang/en_us.json +++ b/src/main/resources/assets/energonrelics/lang/en_us.json @@ -28,5 +28,10 @@ "death.attack.energonrelics.defensive_laser.player": "%s was evaporated by a laser whilst fighting %s", "block.energonrelics.research_complex_generator": "Research Complex Generator", "block.energonrelics.block_breaker": "Block Breaker", - "item.energonrelics.veridium_powder": "Veridium Powder" + "item.energonrelics.veridium_powder": "Veridium Powder", + "effect.energonrelics.veridium_poisoning": "Veridium Poisoning", + "item.minecraft.potion.effect.energonrelics.veridium_poisoning": "Potion of Veridium Poisoning", + "item.minecraft.splash_potion.effect.energonrelics.veridium_poisoning": "Splash Potion of Veridium Poisoning", + "item.minecraft.lingering_potion.effect.energonrelics.veridium_poisoning": "Lingering Potion of Veridium Poisoning", + "item.minecraft.tipped_arrow.effect.energonrelics.veridium_poisoning": "Arrow of Veridium Poisoning" } \ No newline at end of file diff --git a/src/main/resources/assets/energonrelics/textures/mob_effect/veridium_poisoning.png b/src/main/resources/assets/energonrelics/textures/mob_effect/veridium_poisoning.png new file mode 100644 index 0000000..1fd5ecd Binary files /dev/null and b/src/main/resources/assets/energonrelics/textures/mob_effect/veridium_poisoning.png differ diff --git a/src/main/resources/energonrelics.mixins.json b/src/main/resources/energonrelics.mixins.json index 09c1dac..dfc6126 100644 --- a/src/main/resources/energonrelics.mixins.json +++ b/src/main/resources/energonrelics.mixins.json @@ -6,8 +6,10 @@ "MixinAbstractFileResourcePack" ], "mixins": [ + "BrewingRecipeRegistryAccessor", "DamageSourceAccessor", "MixinDefaultBiomeFeatures", + "MixinLivingEntity", "MixinWorld", "RenderPhaseAccessor" ],