pre修改:添加对修改值事件的泛型支持&API方法的扩充(支持修改maxKeepTick)

This commit is contained in:
叁玖领域 2025-10-22 12:54:46 +08:00
parent 44bc1ad92a
commit 7da5fc6c8d
8 changed files with 211 additions and 130 deletions

1
.gitignore vendored
View File

@ -48,3 +48,4 @@ build
/RenderDoc_1.40_64/
/.run/
/.idea/
/mcmodsrepo/

View File

@ -59,7 +59,7 @@ mod_name=Super Lead Rope
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3
# The mod version. See https://semver.org/
mod_version=0.0.0.6-pre4
mod_version=0.0.0.6-pre5
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@ -79,7 +79,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Add leash.
*/
// ADD LEASH
// ADD LEASH
@SuppressWarnings("unused")
@Cancelable
public static class AddLeash extends SuperLeadRopeEvent {
@ -165,7 +165,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Remove leash.
*/
// REMOVE LEASH
// REMOVE LEASH
@SuppressWarnings("unused")
@Cancelable
public static class RemoveLeash extends SuperLeadRopeEvent {
@ -210,7 +210,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Transfer leash.
*/
// TRANSFORM LEASH
// TRANSFORM LEASH
@SuppressWarnings("unused")
@Cancelable
public static class TransferLeash extends SuperLeadRopeEvent {
@ -268,57 +268,44 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Modify value.
*/
// MODIFY LEASH MAX_LEASH_LENGTH / ELASTIC_DISTANCE_SCALE
// MODIFY LEASH MAX_LEASH_LENGTH / ELASTIC_DISTANCE_SCALE
@SuppressWarnings("unused")
@Cancelable
public static class ModifyValue extends SuperLeadRopeEvent {
public static class ModifyValue<T> extends SuperLeadRopeEvent {
@Nullable
private final LeashHolder holder;
@Nullable
private final Double oldValue;
private final T oldValue;
@Nullable
private Double newValue;
private T newValue;
private final Type type;
private final Scope scope;
/**
* The enum Type.
*/
public enum Type {
/**
* Max distance type.
*/
MAX_DISTANCE,
/**
* Elastic distance scale type.
*/
ELASTIC_DISTANCE_SCALE,
}
MAX_DISTANCE(Double.class),
ELASTIC_DISTANCE_SCALE(Double.class),
MAX_KEEP_LEASH_TICKS(Integer.class),
CUSTOM_DATA(String.class); // 支持更多类型
/**
* The enum Scope.
*/
private final Class<?> valueType;
Type(Class<?> valueType) {
this.valueType = valueType;
}
public Class<?> getValueType() {
return valueType;
}
}
public enum Scope {
/**
* Static scope.
*/
STATIC,
/**
* Instance scope.
*/
INSTANCE
INSTANCE,
STATIC
}
/**
* Instantiates a new Modify value.
*
* @param leashedEntity the leashed entity
* @param holderUUID the holder uuid
* @param oldValue the old value
* @param newValue the new value
* @param type the type
*/
public ModifyValue(Entity leashedEntity, UUID holderUUID, @Nullable Double oldValue, @Nullable Double newValue, Type type) {
// 构造方法 - UUID holder
public ModifyValue(Entity leashedEntity, UUID holderUUID,
@Nullable T oldValue, @Nullable T newValue,
Type type) {
super(leashedEntity);
this.holder = new LeashHolder(holderUUID);
this.oldValue = oldValue;
@ -327,16 +314,10 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
this.scope = Scope.INSTANCE;
}
/**
* Instantiates a new Modify value.
*
* @param leashedEntity the leashed entity
* @param knotBlockpos the knot blockpos
* @param oldValue the old value
* @param newValue the new value
* @param type the type
*/
public ModifyValue(Entity leashedEntity, BlockPos knotBlockpos, @Nullable Double oldValue, @Nullable Double newValue, Type type) {
// 构造方法 - BlockPos holder
public ModifyValue(Entity leashedEntity, BlockPos knotBlockpos,
@Nullable T oldValue, @Nullable T newValue,
Type type) {
super(leashedEntity);
this.holder = new LeashHolder(knotBlockpos);
this.oldValue = oldValue;
@ -345,15 +326,10 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
this.scope = Scope.INSTANCE;
}
/**
* Instantiates a new Modify value.
*
* @param leashedEntity the leashed entity
* @param oldValue the old value
* @param newValue the new value
* @param type the type
*/
public ModifyValue(Entity leashedEntity, @Nullable Double oldValue, @Nullable Double newValue, Type type) {
// 构造方法 - 静态作用域
public ModifyValue(Entity leashedEntity,
@Nullable T oldValue, @Nullable T newValue,
Type type) {
super(leashedEntity);
this.holder = null;
this.oldValue = oldValue;
@ -362,66 +338,49 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
this.scope = Scope.STATIC;
}
/**
* Gets holder.
*
* @return the holder
*/
public @Nullable LeashHolder getHolder() {
return holder;
// 类型安全的获取方法
@SuppressWarnings("unchecked")
public <R> R getOldValueAs(Class<R> clazz) {
if (clazz.isInstance(oldValue)) {
return (R) oldValue;
}
return null;
}
/**
* Gets old value.
*
* @return the old value
*/
public @Nullable Double getOldValue() {
return oldValue;
@SuppressWarnings("unchecked")
public <R> R getNewValueAs(Class<R> clazz) {
if (clazz.isInstance(newValue)) {
return (R) newValue;
}
return null;
}
/**
* Gets new value.
*
* @return the new value
*/
public @Nullable Double getNewValue() {
return newValue;
@SuppressWarnings("unchecked")
public T getOldValue() {
return (T) getOldValueAs(type.valueType);
}
@SuppressWarnings("unchecked")
public T getNewValue() {
return (T) getNewValueAs(type.valueType);
}
/**
* Gets type.
*
* @return the type
*/
public Type getType() {
return type;
}
/**
* Gets scope.
*
* @return the scope
*/
public Scope getScope() {
return scope;
}
/**
* Sets new value.
*
* @param newValue the new value
*/
public void setNewValue(@Nullable Double newValue) {
public void setNewValue(@Nullable T newValue) {
if (newValue != null && !type.valueType.isInstance(newValue)) {
throw new IllegalArgumentException(
"Expected value of type " + type.valueType + ", but got " + newValue.getClass());
}
markModified();
this.newValue = newValue;
}
}
/**
* The type Has focus.
*/
// HAS FOCUS
// HAS FOCUS
@SuppressWarnings("unused")
@Cancelable
public static class hasFocus extends SuperLeadRopeEvent {
@ -497,7 +456,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Keep not break tick.
*/
// KEEP NOT BREAK TICK
// KEEP NOT BREAK TICK
@SuppressWarnings("unused")
public static class keepNotBreakTick extends SuperLeadRopeEvent {
private final int remainedTicks;
@ -558,7 +517,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Teleport with holder.
*/
// TELEPORT
// TELEPORT
@Cancelable
@SuppressWarnings("unused")
public static class teleportWithHolder extends SuperLeadRopeEvent {

View File

@ -506,6 +506,58 @@ public interface ILeashData extends INBTSerializable<CompoundTag> {
*/
boolean transferLeash(BlockPos knotPos, Entity newHolder, String reserved);
/**
* Sets max keep ticks.
*
* @param holder the holder
* @param maxKeepTicks the max keep ticks
* @return the max keep ticks
*/
boolean setMaxKeepTicks(Entity holder, int maxKeepTicks);
/**
* Sets max keep ticks.
*
* @param holderUUID the holder uuid
* @param maxKeepTicks the max keep ticks
* @return the max keep ticks
*/
boolean setMaxKeepTicks(UUID holderUUID, int maxKeepTicks);
/**
* Sets max keep ticks.
*
* @param knotPos the knot pos
* @param maxKeepTicks the max keep ticks
* @return the max keep ticks
*/
boolean setMaxKeepTicks(BlockPos knotPos, int maxKeepTicks);
/**
* Gets max keep ticks.
*
* @param holder the holder
* @return the max keep ticks
*/
int getMaxKeepTicks(Entity holder);
/**
* Gets max keep ticks.
*
* @param holderUUID the holder uuid
* @return the max keep ticks
*/
int getMaxKeepTicks(UUID holderUUID);
/**
* Gets max keep ticks.
*
* @param knotPos the knot pos
* @return the max keep ticks
*/
int getMaxKeepTicks(BlockPos knotPos);
/**
* Has leash boolean.
*

View File

@ -171,7 +171,8 @@ public class LeashDataImpl implements ILeashData {
@Override
public void setStaticMaxDistance(@Nullable Double distance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(distance)) return;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, getStaticMaxDistance(), distance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return;
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, getStaticMaxDistance(), distance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return;
staticMaxDistance = distance;
}
@ -212,7 +213,8 @@ public class LeashDataImpl implements ILeashData {
@Override
public void setStaticElasticDistanceScale(@Nullable Double scale) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, getStaticElasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return;
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, getStaticElasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return;
staticElasticDistanceScale = scale;
}
@ -399,7 +401,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(UUID holderUUID, @Nullable Double newMaxDistance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
@ -422,7 +424,7 @@ public class LeashDataImpl implements ILeashData {
@SuppressWarnings("OptionalGetWithoutIsPresent")
public void setMaxDistanceInner(UUID holderUUID, @Nullable Double newMaxDistance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return;
updateLeashInfoInner(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
@ -440,7 +442,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(UUID holderUUID, @Nullable Double newMaxDistance, int newMaxKeepLeashTicks) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
@ -458,7 +460,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(UUID holderUUID, @Nullable Double newMaxDistance, int maxKeepTicks, String reserved) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
@ -476,7 +478,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(BlockPos knotPos, @Nullable Double newMaxDistance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
@ -499,7 +501,7 @@ public class LeashDataImpl implements ILeashData {
@SuppressWarnings("OptionalGetWithoutIsPresent")
public void setMaxDistanceInner(BlockPos knotPos, @Nullable Double newMaxDistance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return;
updateLeashInfoInner(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
@ -517,7 +519,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(BlockPos knotPos, @Nullable Double newMaxDistance, int newMaxKeepLeashTicks) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
@ -535,7 +537,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(BlockPos knotPos, @Nullable Double newMaxDistance, int maxKeepTicks, String reserved) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
@ -561,7 +563,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(UUID holderUUID, @Nullable Double scale) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
@ -584,14 +586,15 @@ public class LeashDataImpl implements ILeashData {
@SuppressWarnings("OptionalGetWithoutIsPresent")
public void setElasticDistanceScaleInner(UUID holderUUID, @Nullable Double scale) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return;
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return;
updateLeashInfoInner(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
old.maxDistance(),
scale,
event.getNewValue(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
));
@ -601,7 +604,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(BlockPos knotPos, @Nullable Double scale) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
@ -624,7 +627,7 @@ public class LeashDataImpl implements ILeashData {
@SuppressWarnings("OptionalGetWithoutIsPresent")
public void setElasticDistanceScaleInner(BlockPos knotPos, @Nullable Double scale) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return;
updateLeashInfoInner(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
@ -657,7 +660,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(UUID holderUUID, @Nullable Double scale, int newMaxKeepLeashTicks) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
@ -675,7 +678,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(UUID holderUUID, @Nullable Double scale, int maxKeepTicks, String reserved) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
@ -693,7 +696,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(BlockPos knotPos, @Nullable Double scale, int newMaxKeepLeashTicks) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
@ -711,7 +714,7 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(BlockPos knotPos, @Nullable Double scale, int newMaxKeepLeashTicks, String reserved) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
SuperLeadRopeEvent.ModifyValue<Double> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
@ -1184,6 +1187,70 @@ public class LeashDataImpl implements ILeashData {
return true;
}
@Override
public boolean setMaxKeepTicks(Entity holder, int maxKeepTicks) {
return holder instanceof SuperLeashKnotEntity superLeashKnotEntity ?
setMaxKeepTicks(superLeashKnotEntity.getPos(), maxKeepTicks) :
setMaxKeepTicks(holder.getUUID(), maxKeepTicks);
}
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Override
public boolean setMaxKeepTicks(UUID holderUUID, int maxKeepTicks) {
if (maxKeepTicks < 0) return false;
LeashInfo info = leashHolders.get(holderUUID);
if (info == null) return false;
SuperLeadRopeEvent.ModifyValue<Integer> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, holderUUID, info.keepLeashTicks(), maxKeepTicks, SuperLeadRopeEvent.ModifyValue.Type.MAX_KEEP_LEASH_TICKS);
if (MinecraftForge.EVENT_BUS.post(event) && (event.getNewValue() == null || event.getNewValue() < 0)) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
old.maxDistance(),
old.elasticDistanceScale(),
event.getNewValue(),
event.getNewValue()
));
}
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Override
public boolean setMaxKeepTicks(BlockPos knotPos, int maxKeepTicks) {
if (maxKeepTicks < 0) return false;
LeashInfo info = leashKnots.get(knotPos);
if (info == null) return false;
SuperLeadRopeEvent.ModifyValue<Integer> event = new SuperLeadRopeEvent.ModifyValue<>(this.entity, knotPos, info.keepLeashTicks(), maxKeepTicks, SuperLeadRopeEvent.ModifyValue.Type.MAX_KEEP_LEASH_TICKS);
if (MinecraftForge.EVENT_BUS.post(event) && (event.getNewValue() == null || event.getNewValue() < 0)) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
old.maxDistance(),
old.elasticDistanceScale(),
event.getNewValue(),
event.getNewValue()
));
}
@Override
public int getMaxKeepTicks(Entity holder) {
return holder instanceof SuperLeashKnotEntity superLeashKnotEntity ?
getMaxKeepTicks(superLeashKnotEntity.getPos()) :
getMaxKeepTicks(holder.getUUID());
}
@Override
public int getMaxKeepTicks(UUID holderUUID) {
return Optional.ofNullable(leashHolders.get(holderUUID)).map(LeashInfo::maxKeepLeashTicks).orElse(-1);
}
@Override
public int getMaxKeepTicks(BlockPos knotPos) {
return Optional.ofNullable(leashKnots.get(knotPos)).map(LeashInfo::maxKeepLeashTicks).orElse(-1);
}
@Override
public boolean hasLeash() {
return !leashKnots.isEmpty() || !leashHolders.isEmpty();

View File

@ -517,7 +517,9 @@ public class LeashDataCommand {
Entity holder = EntityArgument.getEntity(context, "holder");
CommandSourceStack source = context.getSource();
int successCount = 0;
/*
Removed leash from %s[more than 4只显示前4个] held by %s[如果有失败则加上, But no leash found form %s on %s[more than 4 只显示前4个]]
*/
for (Entity target : targets) {
boolean success = LeashDataInnerAPI.LeashOperations.detach(target, holder);

View File

@ -150,7 +150,7 @@ public class MotionCommand {
LiteralArgumentBuilder<CommandSourceStack> Motion = $$motionRoot.requires(cs -> cs.hasPermission(2))
.then(Commands.argument("targets", EntityArgument.entities())
.then(Commands.literal("addApplyEntity")
.then(Commands.literal("add")
.then(Commands.argument("vecX", DoubleArgumentType.doubleArg())
.then(Commands.argument("vecY", DoubleArgumentType.doubleArg())
.then(Commands.argument("vecZ", DoubleArgumentType.doubleArg())
@ -159,7 +159,7 @@ public class MotionCommand {
)
)
)
.then(Commands.literal("setApplyEntity")
.then(Commands.literal("set")
.then(Commands.argument("vecX", DoubleArgumentType.doubleArg())
.then(Commands.argument("vecY", DoubleArgumentType.doubleArg())
.then(Commands.argument("vecZ", DoubleArgumentType.doubleArg())

View File

@ -432,7 +432,7 @@ public enum SLPLangKeyValue {
* The Message leashdata add success.
*/
MESSAGE_LEASHDATA_ADD_SUCCESS(
"command.leashdata.addApplyEntity.success", ModPartEnum.COMMAND,
"command.leashdata.add_apply_entity.success", ModPartEnum.COMMAND,
"§bAdded leash successfully. §a%s §7→ §e%s",
"§b添加拴绳成功. §a%s §7→ §e%s",
"§b添加拴繩成功. §a%s §7→ §e%s",