9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-28 03:19:12 +00:00

Fix particle on 1.20.5+

This commit is contained in:
XiaoMoMi
2024-07-18 23:59:15 +08:00
parent 291ce601c4
commit 076e799016
6 changed files with 53 additions and 51 deletions

View File

@@ -59,8 +59,10 @@ import net.momirealms.customfishing.bukkit.item.damage.CustomDurabilityItem;
import net.momirealms.customfishing.bukkit.totem.particle.DustParticleSetting;
import net.momirealms.customfishing.bukkit.totem.particle.ParticleSetting;
import net.momirealms.customfishing.bukkit.util.ItemStackUtils;
import net.momirealms.customfishing.bukkit.util.ParticleUtils;
import net.momirealms.customfishing.common.dependency.DependencyProperties;
import net.momirealms.customfishing.common.helper.AdventureHelper;
import net.momirealms.customfishing.common.helper.VersionHelper;
import net.momirealms.customfishing.common.item.AbstractItem;
import net.momirealms.customfishing.common.item.Item;
import net.momirealms.customfishing.common.util.*;
@@ -84,6 +86,7 @@ import java.util.function.Function;
public class BukkitConfigManager extends ConfigManager {
private static YamlDocument MAIN_CONFIG;
private static Particle dustParticle;
public static YamlDocument getMainConfig() {
return MAIN_CONFIG;
@@ -99,6 +102,7 @@ public class BukkitConfigManager extends ConfigManager {
this.registerBuiltInEffectModifierParser();
this.registerBuiltInTotemParser();
this.registerBuiltInHookParser();
dustParticle = VersionHelper.isVersionNewerThan1_20_5() ? Particle.valueOf("DUST") : Particle.valueOf("REDSTONE");
}
@Override
@@ -543,6 +547,9 @@ public class BukkitConfigManager extends ConfigManager {
}
private TriConsumer<Effect, Context<Player>, Integer> parseEffect(Section section) {
if (!section.contains("type")) {
throw new RuntimeException(section.getRouteAsString());
}
switch (section.getString("type")) {
case "lava-fishing" -> {
return (((effect, context, phase) -> {
@@ -934,7 +941,7 @@ public class BukkitConfigManager extends ConfigManager {
}
private ParticleSetting getParticleSetting(Section section) {
Particle particle = Particle.valueOf(section.getString("type","REDSTONE"));
Particle particle = ParticleUtils.getParticle(section.getString("type","REDSTONE").toUpperCase(Locale.ENGLISH));
String formulaHorizontal = section.getString("polar-coordinates-formula.horizontal");
String formulaVertical = section.getString("polar-coordinates-formula.vertical");
List<Pair<Double, Double>> ranges = section.getStringList("theta.range")
@@ -942,29 +949,15 @@ public class BukkitConfigManager extends ConfigManager {
String[] split = it.split("~");
return Pair.of(Double.parseDouble(split[0]) * Math.PI / 180, Double.parseDouble(split[1]) * Math.PI / 180);
}).toList();
double interval = section.getDouble("theta.draw-interval", 3d);
int delay = section.getInt("task.delay", 0);
int period = section.getInt("task.period", 0);
if (particle == Particle.REDSTONE) {
if (particle == dustParticle) {
String color = section.getString("options.color","0,0,0");
String[] colorSplit = color.split(",");
return new DustParticleSetting(
formulaHorizontal,
formulaVertical,
particle,
interval,
ranges,
delay,
period,
new Particle.DustOptions(
Color.fromRGB(
Integer.parseInt(colorSplit[0]),
Integer.parseInt(colorSplit[1]),
Integer.parseInt(colorSplit[2])
),
section.getDouble("options.scale", 1.0).floatValue()
)
formulaHorizontal, formulaVertical, particle, interval, ranges, delay, period,
new Particle.DustOptions(Color.fromRGB(Integer.parseInt(colorSplit[0]), Integer.parseInt(colorSplit[1]), Integer.parseInt(colorSplit[2])), section.getDouble("options.scale", 1.0).floatValue())
);
} else if (particle == Particle.DUST_COLOR_TRANSITION) {
String color = section.getString("options.from","0,0,0");
@@ -972,37 +965,15 @@ public class BukkitConfigManager extends ConfigManager {
String toColor = section.getString("options.to","255,255,255");
String[] toColorSplit = toColor.split(",");
return new DustParticleSetting(
formulaHorizontal,
formulaVertical,
particle,
interval,
ranges,
delay,
period,
formulaHorizontal, formulaVertical, particle, interval, ranges, delay, period,
new Particle.DustTransition(
Color.fromRGB(
Integer.parseInt(colorSplit[0]),
Integer.parseInt(colorSplit[1]),
Integer.parseInt(colorSplit[2])
),
Color.fromRGB(
Integer.parseInt(toColorSplit[0]),
Integer.parseInt(toColorSplit[1]),
Integer.parseInt(toColorSplit[2])
),
Color.fromRGB(Integer.parseInt(colorSplit[0]), Integer.parseInt(colorSplit[1]), Integer.parseInt(colorSplit[2])),
Color.fromRGB(Integer.parseInt(toColorSplit[0]), Integer.parseInt(toColorSplit[1]), Integer.parseInt(toColorSplit[2])),
section.getDouble("options.scale", 1.0).floatValue()
)
);
} else {
return new ParticleSetting(
formulaHorizontal,
formulaVertical,
particle,
interval,
ranges,
delay,
period
);
return new ParticleSetting(formulaHorizontal, formulaVertical, particle, interval, ranges, delay, period);
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.bukkit.util;
import net.momirealms.customfishing.common.helper.VersionHelper;
import org.bukkit.Particle;
public class ParticleUtils {
public static Particle getParticle(String particle) {
if (!VersionHelper.isVersionNewerThan1_20_5()) return Particle.valueOf(particle);
return switch (particle) {
case "REDSTONE" -> Particle.valueOf("DUST");
case "VILLAGER_HAPPY" -> Particle.valueOf("HAPPY_VILLAGER");
default -> Particle.valueOf(particle);
};
}
}