Skip to content

Commit

Permalink
[1.20.4] Ported potion effect mod element (MCreator#4550)
Browse files Browse the repository at this point in the history
* Added side indicators to some potion effect triggers

* Support for effect textures

* Port potion effect mod element

* Partially revert change to active tick condition

* Fixes
  • Loading branch information
AlsoSomeoneElse authored Feb 5, 2024
1 parent b915d48 commit 451fed7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 40 deletions.
2 changes: 1 addition & 1 deletion plugins/generator-1.20.4/neoforge-1.20.4/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -29,21 +29,58 @@
-->

<#-- @formatter:off -->
<#include "../procedures.java.ftl">

/*
* MCreator note: This file will be REGENERATED on each build.
*/

package ${package}.init;

public class ${JavaModName}MobEffects {
<#assign effects_that_expire = potioneffects?filter(effect -> hasProcedure(effect.onExpired))>

public static final DeferredRegister<MobEffect> REGISTRY = DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, ${JavaModName}.MODID);
<#if effects_that_expire?size != 0>@Mod.EventBusSubscriber </#if>public class ${JavaModName}MobEffects {

public static final DeferredRegister<MobEffect> REGISTRY = DeferredRegister.create(Registries.MOB_EFFECT, ${JavaModName}.MODID);

<#list potioneffects as effect>
public static final RegistryObject<MobEffect> ${effect.getModElement().getRegistryNameUpper()} =
public static final DeferredHolder<MobEffect, MobEffect> ${effect.getModElement().getRegistryNameUpper()} =
REGISTRY.register("${effect.getModElement().getRegistryName()}", () -> new ${effect.getModElement().getName()}MobEffect());
</#list>

<#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
</#list>
</#compress>
}
</#if>
}

<#-- @formatter:on -->
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.apache.logging.log4j.Logger;
<#if w.hasVariables()>${JavaModName}Variables.ATTACHMENT_TYPES.register(modEventBus);</#if>
<#if w.hasElementsOfType("painting")>${JavaModName}Paintings.REGISTRY.register(modEventBus);</#if>
<#if w.hasElementsOfType("potion")>${JavaModName}Potions.REGISTRY.register(modEventBus);</#if>
<#if w.hasElementsOfType("potioneffect")>${JavaModName}MobEffects.REGISTRY.register(modEventBus);</#if>
<#if w.hasElementsOfType("enchantment")>${JavaModName}Enchantments.REGISTRY.register(modEventBus);</#if>
<#if w.hasElementsOfType("gui")>${JavaModName}Menus.REGISTRY.register(modEventBus);</#if>
<#if w.hasElementsOfType("particle")>${JavaModName}ParticleTypes.REGISTRY.register(modEventBus);</#if>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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>Instantenous</#if>MobEffect {

public ${name}MobEffect() {
super(MobEffectCategory.<#if data.isBad>HARMFUL<#elseif data.isBenefitical>BENEFICIAL<#else>NEUTRAL</#if>, ${data.color.getRGB()});
Expand All @@ -45,12 +44,6 @@ public class ${name}MobEffect extends MobEffect {
return "effect.${modid}.${registryname}";
}

<#if data.isInstant>
@Override public boolean isInstantenous() {
return true;
}
</#if>

<#if hasProcedure(data.onStarted)>
<#if data.isInstant>
@Override public void applyInstantenousEffect(Entity source, Entity indirectSource, LivingEntity entity, int amplifier, double health) {
Expand All @@ -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()",
Expand All @@ -77,23 +70,19 @@ public class ${name}MobEffect extends MobEffect {
</#if>
</#if>

<#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>
}
</#if>

<#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()",
Expand All @@ -104,16 +93,8 @@ public class ${name}MobEffect extends MobEffect {
}
</#if>

@Override public boolean isDurationEffectTick(int duration, int amplifier) {
<#if hasProcedure(data.activeTickCondition)>
return <@procedureOBJToConditionCode data.activeTickCondition/>;
<#else>
return true;
</#if>
}

<#if data.hasCustomRenderer()>
@Override public void initializeClient(java.util.function.Consumer<IClientMobEffectExtensions> consumer) {
@Override public void initializeClient(Consumer<IClientMobEffectExtensions> consumer) {
consumer.accept(new IClientMobEffectExtensions() {
<#if !data.renderStatusInInventory>
@Override public boolean isVisibleInInventory(MobEffectInstance effect) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/mcreator/ui/modgui/PotionEffectGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 451fed7

Please sign in to comment.