9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 08:29:35 +00:00

[Feature] Variation keeps the data

This commit is contained in:
XiaoMoMi
2024-04-27 22:44:16 +08:00
parent e3b2188507
commit d42aae28c8
3 changed files with 17 additions and 1 deletions

View File

@@ -151,6 +151,13 @@ public interface Crop extends KeyItem {
interface Stage { interface Stage {
/**
* Get the crop config
*
* @return crop config
*/
Crop getCrop();
/** /**
* Get the offset of the hologram * Get the offset of the hologram
* *

View File

@@ -494,9 +494,12 @@ public class ActionManagerImpl implements ActionManager {
} }
for (VariationCrop variationCrop : variations) { for (VariationCrop variationCrop : variations) {
if (Math.random() < variationCrop.getChance() + bonus) { if (Math.random() < variationCrop.getChance() + bonus) {
SimpleLocation location = SimpleLocation.of(state.getLocation());
plugin.getItemManager().removeAnythingAt(state.getLocation()); plugin.getItemManager().removeAnythingAt(state.getLocation());
plugin.getWorldManager().removeAnythingAt(SimpleLocation.of(state.getLocation())); plugin.getWorldManager().removeAnythingAt(location);
plugin.getItemManager().placeItem(state.getLocation(), variationCrop.getItemCarrier(), variationCrop.getItemID()); plugin.getItemManager().placeItem(state.getLocation(), variationCrop.getItemCarrier(), variationCrop.getItemID());
Optional.ofNullable(plugin.getItemManager().getCropStageByStageID(variationCrop.getItemID()))
.ifPresent(stage -> plugin.getWorldManager().addCropAt(new MemoryCrop(location, stage.getCrop().getKey(), stage.getPoint()), location));
break; break;
} }
} }

View File

@@ -17,6 +17,7 @@
package net.momirealms.customcrops.mechanic.item.impl; package net.momirealms.customcrops.mechanic.item.impl;
import net.momirealms.customcrops.api.CustomCropsPlugin;
import net.momirealms.customcrops.api.mechanic.action.Action; import net.momirealms.customcrops.api.mechanic.action.Action;
import net.momirealms.customcrops.api.mechanic.action.ActionTrigger; import net.momirealms.customcrops.api.mechanic.action.ActionTrigger;
import net.momirealms.customcrops.api.mechanic.condition.Conditions; import net.momirealms.customcrops.api.mechanic.condition.Conditions;
@@ -206,6 +207,11 @@ public class CropConfig extends AbstractEventItem implements Crop {
this.breakRequirements = breakRequirements; this.breakRequirements = breakRequirements;
} }
@Override
public Crop getCrop() {
return CustomCropsPlugin.get().getItemManager().getCropByStageID(stageID);
}
@Override @Override
public double getHologramOffset() { public double getHologramOffset() {
return hologramOffset; return hologramOffset;