mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-20 15:39:21 +00:00
Improve crop tick
This commit is contained in:
@@ -62,7 +62,7 @@ public class CropBlock extends AbstractCustomCropsBlock {
|
|||||||
// ignore random tick
|
// ignore random tick
|
||||||
if (world.setting().tickCropMode() == 1) return;
|
if (world.setting().tickCropMode() == 1) return;
|
||||||
if (canTick(state, world.setting().tickCropInterval())) {
|
if (canTick(state, world.setting().tickCropInterval())) {
|
||||||
tickCrop(state, world, location, offlineTick);
|
tickCrop(state, world, location, offlineTick, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public class CropBlock extends AbstractCustomCropsBlock {
|
|||||||
// ignore scheduled tick
|
// ignore scheduled tick
|
||||||
if (world.setting().tickCropMode() == 2) return;
|
if (world.setting().tickCropMode() == 2) return;
|
||||||
if (canTick(state, world.setting().tickCropInterval())) {
|
if (canTick(state, world.setting().tickCropInterval())) {
|
||||||
tickCrop(state, world, location, offlineTick);
|
tickCrop(state, world, location, offlineTick, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ public class CropBlock extends AbstractCustomCropsBlock {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tickCrop(CustomCropsBlockState state, CustomCropsWorld<?> world, Pos3 location, boolean offline) {
|
private void tickCrop(CustomCropsBlockState state, CustomCropsWorld<?> world, Pos3 location, boolean offline, boolean tickMode) {
|
||||||
CropConfig config = config(state);
|
CropConfig config = config(state);
|
||||||
BukkitCustomCropsPlugin plugin = BukkitCustomCropsPlugin.getInstance();
|
BukkitCustomCropsPlugin plugin = BukkitCustomCropsPlugin.getInstance();
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
@@ -349,6 +349,9 @@ public class CropBlock extends AbstractCustomCropsBlock {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tickMode && config.ignoreRandomTick()) return;
|
||||||
|
if (!tickMode && config.ignoreScheduledTick()) return;
|
||||||
|
|
||||||
int previousPoint = point(state);
|
int previousPoint = point(state);
|
||||||
World bukkitWorld = world.bukkitWorld();
|
World bukkitWorld = world.bukkitWorld();
|
||||||
Location bukkitLocation = location.toLocation(bukkitWorld);
|
Location bukkitLocation = location.toLocation(bukkitWorld);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package net.momirealms.customcrops.api.core.mechanic.crop;
|
package net.momirealms.customcrops.api.core.mechanic.crop;
|
||||||
|
|
||||||
import net.momirealms.customcrops.api.action.Action;
|
import net.momirealms.customcrops.api.action.Action;
|
||||||
|
import net.momirealms.customcrops.api.core.mechanic.pot.PotConfig;
|
||||||
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
||||||
import net.momirealms.customcrops.api.requirement.Requirement;
|
import net.momirealms.customcrops.api.requirement.Requirement;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -207,6 +208,20 @@ public interface CropConfig {
|
|||||||
return new CropConfigImpl.BuilderImpl();
|
return new CropConfigImpl.BuilderImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the crop ignore scheduled tick?
|
||||||
|
*
|
||||||
|
* @return ignore or not
|
||||||
|
*/
|
||||||
|
boolean ignoreScheduledTick();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the crop ignore random tick?
|
||||||
|
*
|
||||||
|
* @return ignore or not
|
||||||
|
*/
|
||||||
|
boolean ignoreRandomTick();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder interface for constructing instances of {@link CropConfig}.
|
* Builder interface for constructing instances of {@link CropConfig}.
|
||||||
*/
|
*/
|
||||||
@@ -355,5 +370,21 @@ public interface CropConfig {
|
|||||||
* @return The builder instance for chaining.
|
* @return The builder instance for chaining.
|
||||||
*/
|
*/
|
||||||
Builder stages(Collection<CropStageConfig.Builder> stages);
|
Builder stages(Collection<CropStageConfig.Builder> stages);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the crop ignores random tick
|
||||||
|
*
|
||||||
|
* @param ignoreRandomTick True if ignore random tick
|
||||||
|
* @return The current instance of the Builder.
|
||||||
|
*/
|
||||||
|
Builder ignoreRandomTick(boolean ignoreRandomTick);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the crop ignores scheduled tick
|
||||||
|
*
|
||||||
|
* @param ignoreScheduledTick True if ignore scheduled tick
|
||||||
|
* @return The current instance of the Builder.
|
||||||
|
*/
|
||||||
|
Builder ignoreScheduledTick(boolean ignoreScheduledTick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
private final HashMap<String, CropStageConfig> id2Stages = new HashMap<>();
|
private final HashMap<String, CropStageConfig> id2Stages = new HashMap<>();
|
||||||
private final Set<String> stageIDs = new HashSet<>();
|
private final Set<String> stageIDs = new HashSet<>();
|
||||||
private final HashMap<Integer, CropStageConfig> cropStageWithModelMap = new HashMap<>();
|
private final HashMap<Integer, CropStageConfig> cropStageWithModelMap = new HashMap<>();
|
||||||
|
private final boolean ignoreScheduledTick;
|
||||||
|
private final boolean ignoreRandomTick;
|
||||||
|
|
||||||
public CropConfigImpl(
|
public CropConfigImpl(
|
||||||
String id,
|
String id,
|
||||||
@@ -69,7 +71,9 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
BoneMeal[] boneMeals,
|
BoneMeal[] boneMeals,
|
||||||
boolean rotation,
|
boolean rotation,
|
||||||
Set<String> potWhitelist,
|
Set<String> potWhitelist,
|
||||||
Collection<CropStageConfig.Builder> stageBuilders
|
Collection<CropStageConfig.Builder> stageBuilders,
|
||||||
|
boolean ignoreScheduledTick,
|
||||||
|
boolean ignoreRandomTick
|
||||||
) {
|
) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
@@ -88,6 +92,8 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
this.boneMeals = boneMeals;
|
this.boneMeals = boneMeals;
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
this.potWhitelist = potWhitelist;
|
this.potWhitelist = potWhitelist;
|
||||||
|
this.ignoreRandomTick = ignoreRandomTick;
|
||||||
|
this.ignoreScheduledTick = ignoreScheduledTick;
|
||||||
for (CropStageConfig.Builder builder : stageBuilders) {
|
for (CropStageConfig.Builder builder : stageBuilders) {
|
||||||
CropStageConfig config = builder.crop(this).build();
|
CropStageConfig config = builder.crop(this).build();
|
||||||
point2Stages.put(config.point(), config);
|
point2Stages.put(config.point(), config);
|
||||||
@@ -228,8 +234,17 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
return navigablePoint2Stages.floorEntry(point);
|
return navigablePoint2Stages.floorEntry(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BuilderImpl implements Builder {
|
@Override
|
||||||
|
public boolean ignoreScheduledTick() {
|
||||||
|
return ignoreScheduledTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean ignoreRandomTick() {
|
||||||
|
return ignoreRandomTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BuilderImpl implements Builder {
|
||||||
private String id;
|
private String id;
|
||||||
private String seed;
|
private String seed;
|
||||||
private ExistenceForm existenceForm;
|
private ExistenceForm existenceForm;
|
||||||
@@ -249,10 +264,12 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
private boolean rotation;
|
private boolean rotation;
|
||||||
private Set<String> potWhitelist;
|
private Set<String> potWhitelist;
|
||||||
private Collection<CropStageConfig.Builder> stages;
|
private Collection<CropStageConfig.Builder> stages;
|
||||||
|
private boolean ignoreScheduledTick;
|
||||||
|
private boolean ignoreRandomTick;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CropConfig build() {
|
public CropConfig build() {
|
||||||
return new CropConfigImpl(id, seed, maxPoints, wrongPotActions, interactActions, breakActions, plantActions, reachLimitActions, deathActions, plantRequirements, breakRequirements, interactRequirements, growConditions, deathConditions, boneMeals, rotation, potWhitelist, stages);
|
return new CropConfigImpl(id, seed, maxPoints, wrongPotActions, interactActions, breakActions, plantActions, reachLimitActions, deathActions, plantRequirements, breakRequirements, interactRequirements, growConditions, deathConditions, boneMeals, rotation, potWhitelist, stages, ignoreScheduledTick, ignoreRandomTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -361,5 +378,17 @@ public class CropConfigImpl implements CropConfig {
|
|||||||
this.stages = new HashSet<>(stages);
|
this.stages = new HashSet<>(stages);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder ignoreRandomTick(boolean ignoreRandomTick) {
|
||||||
|
this.ignoreRandomTick = ignoreRandomTick;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder ignoreScheduledTick(boolean ignoreScheduledTick) {
|
||||||
|
this.ignoreScheduledTick = ignoreScheduledTick;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,8 +275,20 @@ public interface PotConfig {
|
|||||||
*/
|
*/
|
||||||
Builder isNearbyWaterAccepted(boolean isNearbyWaterAccepted);
|
Builder isNearbyWaterAccepted(boolean isNearbyWaterAccepted);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the pot ignores random tick
|
||||||
|
*
|
||||||
|
* @param ignoreRandomTick True if ignore random tick
|
||||||
|
* @return The current instance of the Builder.
|
||||||
|
*/
|
||||||
Builder ignoreRandomTick(boolean ignoreRandomTick);
|
Builder ignoreRandomTick(boolean ignoreRandomTick);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the pot ignores scheduled tick
|
||||||
|
*
|
||||||
|
* @param ignoreScheduledTick True if ignore scheduled tick
|
||||||
|
* @return The current instance of the Builder.
|
||||||
|
*/
|
||||||
Builder ignoreScheduledTick(boolean ignoreScheduledTick);
|
Builder ignoreScheduledTick(boolean ignoreScheduledTick);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -209,6 +209,8 @@ public class ConfigType {
|
|||||||
.seed(section.getString("seed"))
|
.seed(section.getString("seed"))
|
||||||
.rotation(section.getBoolean("random-rotation", false))
|
.rotation(section.getBoolean("random-rotation", false))
|
||||||
.maxPoints(section.getInt("max-points", 1))
|
.maxPoints(section.getInt("max-points", 1))
|
||||||
|
.ignoreRandomTick(section.getBoolean("ignore-random-tick", false))
|
||||||
|
.ignoreScheduledTick(section.getBoolean("ignore-scheduled-tick", false))
|
||||||
.potWhitelist(new HashSet<>(section.getStringList("pot-whitelist")))
|
.potWhitelist(new HashSet<>(section.getStringList("pot-whitelist")))
|
||||||
.wrongPotActions(pam.parseActions(section.getSection("events.wrong_pot")))
|
.wrongPotActions(pam.parseActions(section.getSection("events.wrong_pot")))
|
||||||
.plantActions(pam.parseActions(section.getSection("events.plant")))
|
.plantActions(pam.parseActions(section.getSection("events.plant")))
|
||||||
|
|||||||
Reference in New Issue
Block a user