9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-20 15:39:36 +00:00

checkpoint - 20

This commit is contained in:
XiaoMoMi
2024-07-02 02:41:55 +08:00
parent 214292ad5a
commit 71de6ea626
16 changed files with 359 additions and 52 deletions

View File

@@ -9,6 +9,7 @@ import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.entity.EntityConfig;
@@ -22,6 +23,7 @@ import net.momirealms.customfishing.common.config.node.Node;
import net.momirealms.customfishing.common.item.Item;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import net.momirealms.customfishing.common.util.Pair;
import net.momirealms.customfishing.common.util.TriConsumer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack;
@@ -71,7 +73,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
protected EventPriority eventPriority;
protected Requirement<Player>[] mechanicRequirements;
protected boolean enableBag;
protected List<TriConsumer<Effect, Context<Player>, Integer>> globalEffects;
protected ConfigManager(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
@@ -186,6 +188,10 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
return instance.mechanicRequirements;
}
public static List<TriConsumer<Effect, Context<Player>, Integer>> globalEffects() {
return instance.globalEffects;
}
public void registerHookParser(Function<Object, Consumer<HookConfig.Builder>> function, String... nodes) {
registerNodeFunction(nodes, new HookParserFunction(function));
}

View File

@@ -101,7 +101,16 @@ public class ConfigType {
}
);
private static final ConfigType[] values = new ConfigType[] {ITEM, ENTITY, BLOCK, HOOK, ROD, BAIT, UTIL, TOTEM};
public static final ConfigType ENCHANT = of(
"enchant",
(id, section, functions) -> {
EnchantConfigParser config = new EnchantConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.ENCHANT);
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
private static final ConfigType[] values = new ConfigType[] {ITEM, ENTITY, BLOCK, HOOK, ROD, BAIT, UTIL, TOTEM, ENCHANT};
public static ConfigType[] values() {
return values;

View File

@@ -0,0 +1,77 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.config.function.ConfigParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EffectModifierParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EventParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.TotemParserFunction;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.totem.TotemConfig;
import net.momirealms.customfishing.common.config.node.Node;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public class EnchantConfigParser {
private final String id;
private final List<Consumer<EventCarrier.Builder>> eventBuilderConsumers = new ArrayList<>();
private final List<Consumer<EffectModifier.Builder>> effectBuilderConsumers = new ArrayList<>();
public EnchantConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
analyze(section, functionMap);
}
private void analyze(Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
Map<String, Object> dataMap = section.getStringRouteMappedValues(false);
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
String key = entry.getKey();
Node<ConfigParserFunction> node = functionMap.get(key);
if (node == null) continue;
ConfigParserFunction function = node.nodeValue();
if (function != null) {
switch (function.type()) {
case EVENT -> {
EventParserFunction eventParserFunction = (EventParserFunction) function;
Consumer<EventCarrier.Builder> consumer = eventParserFunction.accept(entry.getValue());
eventBuilderConsumers.add(consumer);
}
case EFFECT_MODIFIER -> {
EffectModifierParserFunction effectModifierParserFunction = (EffectModifierParserFunction) function;
Consumer<EffectModifier.Builder> consumer = effectModifierParserFunction.accept(entry.getValue());
effectBuilderConsumers.add(consumer);
}
}
continue;
}
if (entry.getValue() instanceof Section innerSection) {
analyze(innerSection, node.getChildTree());
}
}
}
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.TOTEM);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
public EffectModifier getEffectModifier() {
EffectModifier.Builder builder = EffectModifier.builder()
.id(id)
.type(MechanicType.TOTEM);
for (Consumer<EffectModifier.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
return builder.build();
}
}

View File

@@ -25,7 +25,6 @@ public class TotemConfigParser {
public TotemConfigParser(String id, Section section, Map<String, Node<ConfigParserFunction>> functionMap) {
this.id = id;
if (!section.contains("tag")) section.set("tag", true);
analyze(section, functionMap);
}

View File

@@ -204,8 +204,8 @@ public class EffectImpl implements Effect {
this.difficultyAdder += another.difficultyAdder();
this.gameTimeMultiplier += (another.gameTimeMultiplier() - 1);
this.gameTimeAdder += another.gameTimeAdder();
this.waitTimeAdder += (another.waitTimeAdder() -1);
this.waitTimeMultiplier += (another.waitTimeMultiplier() -1);
this.waitTimeAdder += (another.waitTimeAdder());
this.multipleLootChance += another.multipleLootChance();
this.weightOperations.addAll(another.weightOperations());
this.weightOperationsIgnored.addAll(another.weightOperationsIgnored());

View File

@@ -6,9 +6,9 @@ import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.context.ContextKeys;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
import net.momirealms.customfishing.api.storage.user.UserData;
import net.momirealms.customfishing.common.util.Pair;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -102,6 +102,13 @@ public class FishingGears {
context.arg(ContextKeys.ROD, rodID);
BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(rodID, MechanicType.ROD).ifPresent(fishingGears.modifiers::add);
// set enchantments
List<Pair<String, Short>> enchants = BukkitCustomFishingPlugin.getInstance().getIntegrationManager().getEnchantments(rodOnMainHand ? mainHandItem : offHandItem);
for (Pair<String, Short> enchantment : enchants) {
String effectID = enchantment.left() + ":" + enchantment.right();
BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(effectID, MechanicType.ENCHANT).ifPresent(fishingGears.modifiers::add);
}
// set bait if it is
boolean hasBait = false;
String anotherItemID = BukkitCustomFishingPlugin.getInstance().getItemManager().getItemID(rodOnMainHand ? offHandItem : mainHandItem);
@@ -158,6 +165,14 @@ public class FishingGears {
for (String id : totemIDs) {
BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(id, MechanicType.TOTEM).ifPresent(fishingGears.modifiers::add);
}
// add global effects
fishingGears.modifiers.add(
EffectModifier.builder()
.id("__GLOBAL__")
.modifiers(ConfigManager.globalEffects())
.build()
);
};
}

View File

@@ -1,17 +1,39 @@
package net.momirealms.customfishing.api.mechanic.fishing.hook;
import io.papermc.paper.block.fluid.FluidData;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.config.ConfigManager;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.context.ContextKeys;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.effect.EffectProperties;
import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask;
import net.momirealms.customfishing.common.util.RandomUtils;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.Vector;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
public class LavaFishingMechanic implements HookMechanic {
private final FishHook hook;
private final Effect gearsEffect;
private final Context<Player> context;
private ArmorStand tempEntity;
private SchedulerTask task;
private int timeUntilLured;
private int timeUntilHooked;
private int nibble;
private boolean hooked;
private float fishAngle;
private int currentState;
private int jumpTimer;
public LavaFishingMechanic(FishHook hook, Effect gearsEffect, Context<Player> context) {
this.hook = hook;
@@ -24,12 +46,17 @@ public class LavaFishingMechanic implements HookMechanic {
if (!(boolean) gearsEffect.properties().getOrDefault(EffectProperties.LAVA_FISHING, false)) {
return false;
}
return false;
float lavaHeight = 0F;
FluidData fluidData = this.hook.getWorld().getFluidData(this.hook.getLocation());
if (fluidData.getFluidType() == Fluid.LAVA || fluidData.getFluidType() == Fluid.FLOWING_LAVA) {
lavaHeight = (float) (fluidData.getLevel() * 0.125);
}
return lavaHeight > 0 && this.hook.getY() % 1 <= lavaHeight;
}
@Override
public boolean shouldStop() {
return false;
return hook.isOnGround() || (hook.getLocation().getBlock().getType() != Material.LAVA && hook.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.LAVA);
}
@Override
@@ -39,16 +66,123 @@ public class LavaFishingMechanic implements HookMechanic {
@Override
public void start(Effect finalEffect) {
this.setWaitTime(finalEffect);
this.task = BukkitCustomFishingPlugin.getInstance().getScheduler().sync().runRepeating(() -> {
float lavaHeight = 0F;
FluidData fluidData = this.hook.getWorld().getFluidData(this.hook.getLocation());
if (fluidData.getFluidType() == Fluid.LAVA || fluidData.getFluidType() == Fluid.FLOWING_LAVA) {
lavaHeight = (float) (fluidData.getLevel() * 0.125);
}
if (this.nibble > 0) {
--this.nibble;
if (this.hook.getY() % 1 <= lavaHeight) {
this.jumpTimer++;
if (this.jumpTimer >= 4) {
this.jumpTimer = 0;
Vector previousVector = this.hook.getVelocity();
this.hook.setVelocity(new Vector(0,0.24,0));
}
}
if (this.nibble <= 0) {
this.timeUntilLured = 0;
this.timeUntilHooked = 0;
this.hooked = false;
this.jumpTimer = 0;
this.currentState = 0;
}
} else {
if (this.hook.getY() % 1 <= lavaHeight) {
Vector previousVector = this.hook.getVelocity();
this.hook.setVelocity(new Vector(previousVector.getX() * 0.6, Math.min(0.1, Math.max(-0.1, previousVector.getY() + 0.1)), previousVector.getZ() * 0.6));
this.currentState = 1;
} else {
if (currentState == 1) {
this.currentState = 0;
// set temp entity
this.tempEntity = this.hook.getWorld().spawn(this.hook.getLocation().clone().subtract(0,1,0), ArmorStand.class);
this.setTempEntityProperties(this.tempEntity);
this.hook.setHookedEntity(this.tempEntity);
}
}
float f;
float f1;
float f2;
double d0;
double d1;
double d2;
if (this.timeUntilHooked > 0) {
this.timeUntilHooked -= 1;
if (this.timeUntilHooked > 0) {
this.fishAngle += (float) RandomUtils.triangle(0.0D, 9.188D);
f = this.fishAngle * 0.017453292F;
f1 = (float) Math.sin(f);
f2 = (float) Math.cos(f);
d0 = hook.getX() + (double) (f1 * (float) this.timeUntilHooked * 0.1F);
d1 = hook.getY();
d2 = hook.getZ() + (double) (f2 * (float) this.timeUntilHooked * 0.1F);
if (RandomUtils.generateRandomFloat(0,1) < 0.15F) {
hook.getWorld().spawnParticle(Particle.FLAME, d0, d1 - 0.10000000149011612D, d2, 1, f1, 0.1D, f2, 0.0D);
}
float f3 = f1 * 0.04F;
float f4 = f2 * 0.04F;
hook.getWorld().spawnParticle(Particle.FLAME, d0, d1, d2, 0, f4, 0.01D, -f3, 1.0D);
} else {
double d3 = hook.getY() + 0.5D;
hook.getWorld().spawnParticle(Particle.FLAME, hook.getX(), d3, hook.getZ(), (int) (1.0F + 0.3 * 20.0F), 0.3, 0.0D, 0.3, 0.20000000298023224D);
this.nibble = RandomUtils.generateRandomInt(20, 40);
this.hooked = true;
hook.getWorld().playSound(hook.getLocation(), Sound.ENTITY_GENERIC_EXTINGUISH_FIRE, 0.25F, 1.0F + (RandomUtils.generateRandomFloat(0,1)-RandomUtils.generateRandomFloat(0,1)) * 0.4F);
if (this.tempEntity != null && this.tempEntity.isValid()) {
this.tempEntity.remove();
}
}
} else if (timeUntilLured > 0) {
timeUntilLured--;
if (this.timeUntilLured <= 0) {
this.fishAngle = RandomUtils.generateRandomFloat(0F, 360F);
this.timeUntilHooked = RandomUtils.generateRandomInt(20, 80);
}
} else {
setWaitTime(finalEffect);
}
}
}, 1, 1, hook.getLocation());
}
@Override
public boolean isHooked() {
return false;
return hooked;
}
@Override
public void destroy() {
if (this.tempEntity != null && this.tempEntity.isValid()) {
this.tempEntity.remove();
}
if (this.task != null) {
this.task.cancel();
}
}
private void setWaitTime(Effect effect) {
int before = ThreadLocalRandom.current().nextInt(ConfigManager.lavaMaxTime() - ConfigManager.lavaMinTime() + 1) + ConfigManager.lavaMinTime();
int after = Math.max(1, (int) (before * effect.waitTimeMultiplier() + effect.waitTimeAdder()));
BukkitCustomFishingPlugin.getInstance().debug("Wait time: " + before + " -> " + after + " ticks");
this.timeUntilLured = after;
}
private void setTempEntityProperties(ArmorStand entity) {
entity.setInvisible(true);
entity.setCollidable(false);
entity.setInvulnerable(true);
entity.setVisible(false);
entity.setCustomNameVisible(false);
entity.setSmall(true);
entity.setGravity(false);
entity.getPersistentDataContainer().set(
Objects.requireNonNull(NamespacedKey.fromString("temp-entity", BukkitCustomFishingPlugin.getInstance().getBoostrap())),
PersistentDataType.STRING,
"lava"
);
}
}

View File

@@ -5,16 +5,15 @@ import net.momirealms.customfishing.api.mechanic.config.ConfigManager;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.context.ContextKeys;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.effect.EffectProperties;
import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask;
import net.momirealms.customfishing.common.util.RandomUtils;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.persistence.PersistentDataType;
import java.util.Objects;
@@ -113,6 +112,7 @@ public class VoidFishingMechanic implements HookMechanic {
hook.getWorld().spawnParticle(Particle.END_ROD, hook.getX(), d3, hook.getZ(), (int) (1.0F + 0.3 * 20.0F), 0.3, 0.0D, 0.3, 0.20000000298023224D);
this.nibble = RandomUtils.generateRandomInt(20, 40);
this.hooked = true;
hook.getWorld().playSound(hook.getLocation(), Sound.ITEM_TRIDENT_THUNDER, 0.25F, 1.0F + (RandomUtils.generateRandomFloat(0,1)-RandomUtils.generateRandomFloat(0,1)) * 0.4F);
}
} else if (timeUntilLured > 0) {
timeUntilLured--;

View File

@@ -17,6 +17,7 @@ public class MechanicType {
public static final MechanicType BAIT = of("bait");
public static final MechanicType HOOK = of("hook");
public static final MechanicType TOTEM = of("totem");
public static final MechanicType ENCHANT = of("enchant");
private final String type;