diff --git a/plugins/generator-1.20.4/neoforge-1.20.4/generator.yaml b/plugins/generator-1.20.4/neoforge-1.20.4/generator.yaml index 08c78278e74..739c2d57a29 100644 --- a/plugins/generator-1.20.4/neoforge-1.20.4/generator.yaml +++ b/plugins/generator-1.20.4/neoforge-1.20.4/generator.yaml @@ -44,7 +44,7 @@ structures_dir: "@MODDATAROOT/structures" #block_textures_dir: "@MODASSETSROOT/textures/block" #item_textures_dir: "@MODASSETSROOT/textures/item" #entity_textures_dir: "@MODASSETSROOT/textures/entities" -#effect_textures_dir: "@MODASSETSROOT/textures/mob_effect" +effect_textures_dir: "@MODASSETSROOT/textures/mob_effect" particle_textures_dir: "@MODASSETSROOT/textures/particle" screen_textures_dir: "@MODASSETSROOT/textures/screens" #armor_textures_dir: "@MODASSETSROOT/textures/models/armor" diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/potioneffect.definition.yaml b/plugins/generator-1.20.4/neoforge-1.20.4/potioneffect.definition.yaml similarity index 100% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/potioneffect.definition.yaml rename to plugins/generator-1.20.4/neoforge-1.20.4/potioneffect.definition.yaml diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/elementinits/potioneffects.java.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/elementinits/potioneffects.java.ftl similarity index 51% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/elementinits/potioneffects.java.ftl rename to plugins/generator-1.20.4/neoforge-1.20.4/templates/elementinits/potioneffects.java.ftl index 809ebd6db87..54401b27d92 100644 --- a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/elementinits/potioneffects.java.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/elementinits/potioneffects.java.ftl @@ -1,7 +1,7 @@ <#-- # MCreator (https://mcreator.net/) # Copyright (C) 2012-2020, Pylo - # Copyright (C) 2020-2023, Pylo, opensource contributors + # Copyright (C) 2020-2024, Pylo, opensource contributors # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ --> <#-- @formatter:off --> +<#include "../procedures.java.ftl"> /* * MCreator note: This file will be REGENERATED on each build. @@ -36,14 +37,50 @@ package ${package}.init; -public class ${JavaModName}MobEffects { +<#assign effects_that_expire = potioneffects?filter(effect -> hasProcedure(effect.onExpired))> - public static final DeferredRegister REGISTRY = DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, ${JavaModName}.MODID); +<#if effects_that_expire?size != 0>@Mod.EventBusSubscriber public class ${JavaModName}MobEffects { + + public static final DeferredRegister REGISTRY = DeferredRegister.create(Registries.MOB_EFFECT, ${JavaModName}.MODID); <#list potioneffects as effect> - public static final RegistryObject ${effect.getModElement().getRegistryNameUpper()} = + public static final DeferredHolder ${effect.getModElement().getRegistryNameUpper()} = REGISTRY.register("${effect.getModElement().getRegistryName()}", () -> new ${effect.getModElement().getName()}MobEffect()); + + <#if effects_that_expire?size != 0> + @SubscribeEvent public static void onEffectRemoved(MobEffectEvent.Remove event) { + MobEffectInstance effectInstance = event.getEffectInstance(); + if (effectInstance != null) { + expireEffects(event.getEntity(), effectInstance); + } + } + + @SubscribeEvent public static void onEffectExpired(MobEffectEvent.Expired event) { + MobEffectInstance effectInstance = event.getEffectInstance(); + if (effectInstance != null) { + expireEffects(event.getEntity(), effectInstance); + } + } + + private static void expireEffects(Entity entity, MobEffectInstance effectInstance) { + <#compress> + MobEffect effect = effectInstance.getEffect(); + <#list effects_that_expire as effect> + if (effect == ${effect.getModElement().getRegistryNameUpper()}.get()) { + <@procedureCode effect.onExpired, { + "x": "entity.getX()", + "y": "entity.getY()", + "z": "entity.getZ()", + "world": "entity.level()", + "entity": "entity", + "amplifier": "effectInstance.getAmplifier()" + }/> + }<#sep>else + + + } + } <#-- @formatter:on --> \ No newline at end of file diff --git a/plugins/generator-1.20.4/neoforge-1.20.4/templates/modbase/mod.java.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/modbase/mod.java.ftl index c7fc773a0d8..48df5c72391 100644 --- a/plugins/generator-1.20.4/neoforge-1.20.4/templates/modbase/mod.java.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/modbase/mod.java.ftl @@ -33,6 +33,7 @@ import org.apache.logging.log4j.Logger; <#if w.hasVariables()>${JavaModName}Variables.ATTACHMENT_TYPES.register(modEventBus); <#if w.hasElementsOfType("painting")>${JavaModName}Paintings.REGISTRY.register(modEventBus); <#if w.hasElementsOfType("potion")>${JavaModName}Potions.REGISTRY.register(modEventBus); + <#if w.hasElementsOfType("potioneffect")>${JavaModName}MobEffects.REGISTRY.register(modEventBus); <#if w.hasElementsOfType("enchantment")>${JavaModName}Enchantments.REGISTRY.register(modEventBus); <#if w.hasElementsOfType("gui")>${JavaModName}Menus.REGISTRY.register(modEventBus); <#if w.hasElementsOfType("particle")>${JavaModName}ParticleTypes.REGISTRY.register(modEventBus); diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/potioneffect.java.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/potioneffect.java.ftl similarity index 73% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/potioneffect.java.ftl rename to plugins/generator-1.20.4/neoforge-1.20.4/templates/potioneffect.java.ftl index 95fab4c7466..72975ee4729 100644 --- a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/potioneffect.java.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/potioneffect.java.ftl @@ -1,7 +1,7 @@ <#-- # MCreator (https://mcreator.net/) # Copyright (C) 2012-2020, Pylo - # Copyright (C) 2020-2023, Pylo, opensource contributors + # Copyright (C) 2020-2024, Pylo, opensource contributors # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,13 +29,12 @@ --> <#-- @formatter:off --> -<#include "mcitems.ftl"> <#include "procedures.java.ftl"> package ${package}.potion; <#compress> -public class ${name}MobEffect extends MobEffect { +public class ${name}MobEffect extends <#if data.isInstant>InstantenousMobEffect { public ${name}MobEffect() { super(MobEffectCategory.<#if data.isBad>HARMFUL<#elseif data.isBenefitical>BENEFICIAL<#else>NEUTRAL, ${data.color.getRGB()}); @@ -45,12 +44,6 @@ public class ${name}MobEffect extends MobEffect { return "effect.${modid}.${registryname}"; } - <#if data.isInstant> - @Override public boolean isInstantenous() { - return true; - } - - <#if hasProcedure(data.onStarted)> <#if data.isInstant> @Override public void applyInstantenousEffect(Entity source, Entity indirectSource, LivingEntity entity, int amplifier, double health) { @@ -64,7 +57,7 @@ public class ${name}MobEffect extends MobEffect { }/> } <#else> - @Override public void addAttributeModifiers(LivingEntity entity, AttributeMap attributeMap, int amplifier) { + @Override public void onEffectStarted(LivingEntity entity, int amplifier) { <@procedureCode data.onStarted, { "x": "entity.getX()", "y": "entity.getY()", @@ -77,23 +70,19 @@ public class ${name}MobEffect extends MobEffect { - <#if hasProcedure(data.onActiveTick)> - @Override public void applyEffectTick(LivingEntity entity, int amplifier) { - <@procedureCode data.onActiveTick, { - "x": "entity.getX()", - "y": "entity.getY()", - "z": "entity.getZ()", - "world": "entity.level()", - "entity": "entity", - "amplifier": "amplifier" - }/> + <#if hasProcedure(data.activeTickCondition) || hasProcedure(data.onActiveTick)> + @Override public boolean shouldApplyEffectTickThisTick(int duration, int amplifier) { + <#if hasProcedure(data.activeTickCondition)> + return <@procedureOBJToConditionCode data.activeTickCondition/>; + <#else> + return true; + } - <#if hasProcedure(data.onExpired)> - @Override public void removeAttributeModifiers(LivingEntity entity, AttributeMap attributeMap, int amplifier) { - super.removeAttributeModifiers(entity, attributeMap, amplifier); - <@procedureCode data.onExpired, { + <#if hasProcedure(data.onActiveTick)> + @Override public void applyEffectTick(LivingEntity entity, int amplifier) { + <@procedureCode data.onActiveTick, { "x": "entity.getX()", "y": "entity.getY()", "z": "entity.getZ()", @@ -104,16 +93,8 @@ public class ${name}MobEffect extends MobEffect { } - @Override public boolean isDurationEffectTick(int duration, int amplifier) { - <#if hasProcedure(data.activeTickCondition)> - return <@procedureOBJToConditionCode data.activeTickCondition/>; - <#else> - return true; - - } - <#if data.hasCustomRenderer()> - @Override public void initializeClient(java.util.function.Consumer consumer) { + @Override public void initializeClient(Consumer consumer) { consumer.accept(new IClientMobEffectExtensions() { <#if !data.renderStatusInInventory> @Override public boolean isVisibleInInventory(MobEffectInstance effect) { diff --git a/src/main/java/net/mcreator/ui/modgui/PotionEffectGUI.java b/src/main/java/net/mcreator/ui/modgui/PotionEffectGUI.java index ad5f7d0ebe9..1179d261d13 100644 --- a/src/main/java/net/mcreator/ui/modgui/PotionEffectGUI.java +++ b/src/main/java/net/mcreator/ui/modgui/PotionEffectGUI.java @@ -75,13 +75,13 @@ public PotionEffectGUI(MCreator mcreator, ModElement modElement, boolean editing @Override protected void initGUI() { onStarted = new ProcedureSelector(this.withEntry("potioneffect/when_potion_applied"), mcreator, - L10N.t("elementgui.potioneffect.event_potion_applied"), + L10N.t("elementgui.potioneffect.event_potion_applied"), ProcedureSelector.Side.SERVER, Dependency.fromString("entity:entity/x:number/y:number/z:number/world:world/amplifier:number")); onActiveTick = new ProcedureSelector(this.withEntry("potioneffect/when_active_tick"), mcreator, L10N.t("elementgui.potioneffect.event_potion_tick"), Dependency.fromString("entity:entity/x:number/y:number/z:number/world:world/amplifier:number")); onExpired = new ProcedureSelector(this.withEntry("potioneffect/when_potion_expires"), mcreator, - L10N.t("elementgui.potioneffect.event_potion_expires"), + L10N.t("elementgui.potioneffect.event_potion_expires"), ProcedureSelector.Side.SERVER, Dependency.fromString("entity:entity/x:number/y:number/z:number/world:world/amplifier:number")); activeTickCondition = new ProcedureSelector(this.withEntry("potioneffect/active_tick_condition"), mcreator, L10N.t("elementgui.potioneffect.event_tick_condition"), VariableTypeLoader.BuiltInTypes.LOGIC,