Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle scaling #4720

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions plugins/generator-1.20.1/forge-1.20.1/templates/particle.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
Expand Down Expand Up @@ -64,7 +64,7 @@ package ${package}.client.particle;
this.spriteSet = spriteSet;

this.setSize(${data.width}f, ${data.height}f);
<#if data.scale != 1>this.quadSize *= ${data.scale}f;</#if>
<#if !hasProcedure(data.scale)>this.quadSize *= ${data.scale}f;</#if>
KlemenDEV marked this conversation as resolved.
Show resolved Hide resolved

<#if (data.maxAgeDiff > 0)>
this.lifetime = (int) Math.max(1, ${data.maxAge} + (this.random.nextInt(${data.maxAgeDiff * 2}) - ${data.maxAgeDiff}));
Expand Down Expand Up @@ -101,6 +101,14 @@ package ${package}.client.particle;
return ParticleRenderType.PARTICLE_SHEET_${data.renderType};
}


<#if hasProcedure(data.scale)>
@Override public float getQuadSize(float scale) {
Level world = this.level;
return (float) <@procedureOBJToConditionCode data.scale/>;
}
</#if>

@Override public void tick() {
super.tick();

Expand Down
Expand Up @@ -53,7 +53,7 @@ package ${package}.client.particle;
}

private final SpriteSet spriteSet;

<#if data.angularVelocity != 0 || data.angularAcceleration != 0>
private float angularVelocity;
private float angularAcceleration;
Expand All @@ -64,7 +64,7 @@ package ${package}.client.particle;
this.spriteSet = spriteSet;

this.setSize(${data.width}f, ${data.height}f);
<#if data.scale != 1>this.quadSize *= ${data.scale}f;</#if>
<#if !hasProcedure(data.scale)>this.quadSize *= ${data.scale}f;</#if>

<#if (data.maxAgeDiff > 0)>
this.lifetime = (int) Math.max(1, ${data.maxAge} + (this.random.nextInt(${data.maxAgeDiff * 2}) - ${data.maxAgeDiff}));
Expand Down Expand Up @@ -101,6 +101,14 @@ package ${package}.client.particle;
return ParticleRenderType.PARTICLE_SHEET_${data.renderType};
}


<#if hasProcedure(data.scale)>
@Override public float getQuadSize(float scale) {
Level world = this.level;
return (float) <@procedureOBJToConditionCode data.scale/>;
}
</#if>

@Override public void tick() {
super.tick();

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/mcreator/element/types/Particle.java
Expand Up @@ -19,6 +19,7 @@
package net.mcreator.element.types;

import net.mcreator.element.GeneratableElement;
import net.mcreator.element.parts.procedure.NumberProcedure;
import net.mcreator.element.parts.procedure.Procedure;
import net.mcreator.io.FileIO;
import net.mcreator.minecraft.MinecraftImageGenerator;
Expand All @@ -45,7 +46,7 @@ public class Particle extends GeneratableElement {

public double width;
public double height;
public double scale;
KlemenDEV marked this conversation as resolved.
Show resolved Hide resolved
public NumberProcedure scale;
public double speedFactor;
public double gravity;
public int maxAge;
Expand All @@ -55,7 +56,7 @@ public class Particle extends GeneratableElement {

public boolean canCollide;
public boolean alwaysShow;

KlemenDEV marked this conversation as resolved.
Show resolved Hide resolved
public String renderType;

public Procedure additionalExpiryCondition;
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/net/mcreator/ui/modgui/ParticleGUI.java
Expand Up @@ -29,6 +29,8 @@
import net.mcreator.ui.help.HelpUtils;
import net.mcreator.ui.init.L10N;
import net.mcreator.ui.minecraft.TextureHolder;
import net.mcreator.ui.procedure.AbstractProcedureSelector;
import net.mcreator.ui.procedure.NumberProcedureSelector;
import net.mcreator.ui.procedure.ProcedureSelector;
import net.mcreator.ui.validation.AggregatedValidationResult;
import net.mcreator.ui.validation.validators.TileHolderValidator;
Expand All @@ -49,7 +51,7 @@ public class ParticleGUI extends ModElementGUI<Particle> {

private final JSpinner width = new JSpinner(new SpinnerNumberModel(0.2, 0, 4096, 0.1));
private final JSpinner height = new JSpinner(new SpinnerNumberModel(0.2, 0, 4096, 0.1));
private final JSpinner scale = new JSpinner(new SpinnerNumberModel(1, 0.1, 4096, 0.1));
private NumberProcedureSelector scale;
private final JSpinner gravity = new JSpinner(new SpinnerNumberModel(0, -100, 100, 0.1));
private final JSpinner speedFactor = new JSpinner(new SpinnerNumberModel(1, -100, 100, 0.1));
private final JSpinner maxAge = new JSpinner(new SpinnerNumberModel(7, 0, 100000, 1));
Expand All @@ -73,6 +75,10 @@ public ParticleGUI(MCreator mcreator, ModElement modElement, boolean editingMode
}

@Override protected void initGUI() {
scale = new NumberProcedureSelector(this.withEntry("particle/scale"), mcreator,
L10N.t("elementgui.particle.visual_scale"), AbstractProcedureSelector.Side.CLIENT,
new JSpinner(new SpinnerNumberModel(1, 0.1, 4096, 0.1)), 0,
Dependency.fromString("x:number/y:number/z:number/world:world/age:number/scale:number"));
additionalExpiryCondition = new ProcedureSelector(this.withEntry("particle/additional_expiry_condition"),
mcreator, L10N.t("elementgui.particle.expiry_condition"), ProcedureSelector.Side.CLIENT, true,
VariableTypeLoader.BuiltInTypes.LOGIC, Dependency.fromString(
Expand Down Expand Up @@ -160,6 +166,7 @@ public ParticleGUI(MCreator mcreator, ModElement modElement, boolean editingMode
super.reloadDataLists();

additionalExpiryCondition.refreshListKeepSelected();
scale.refreshListKeepSelected();
}

@Override protected AggregatedValidationResult validatePage(int page) {
Expand All @@ -173,7 +180,7 @@ public ParticleGUI(MCreator mcreator, ModElement modElement, boolean editingMode
StringUtils.removeEnd(particle.texture, ".png")); // legacy, old workspaces stored name with extension
width.setValue(particle.width);
height.setValue(particle.height);
scale.setValue(particle.scale);
scale.setSelectedProcedure(particle.scale);
gravity.setValue(particle.gravity);
speedFactor.setValue(particle.speedFactor);
frameDuration.setValue(particle.frameDuration);
Expand All @@ -193,7 +200,7 @@ public ParticleGUI(MCreator mcreator, ModElement modElement, boolean editingMode
particle.texture = texture.getID() + ".png"; // legacy, old workspaces stored name with extension
particle.width = (double) width.getValue();
particle.height = (double) height.getValue();
particle.scale = (double) scale.getValue();
particle.scale = scale.getSelectedProcedure();
particle.gravity = (double) gravity.getValue();
particle.speedFactor = (double) speedFactor.getValue();
particle.maxAge = (int) maxAge.getValue();
Expand Down
Expand Up @@ -1425,7 +1425,7 @@ Color.white, new Procedure("condition4"),
particle.width = 2.3;
particle.frameDuration = 2;
particle.height = 1.38;
particle.scale = 1.38;
particle.scale = new NumberProcedure(emptyLists ? null : "number1", 1.38);
particle.gravity = 12.3;
particle.speedFactor = 1.3;
particle.canCollide = _true;
Expand Down