Skip to content

Commit

Permalink
Better auto sync data (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china authored Sep 23, 2023
1 parent 1cacbfa commit c96a0bd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
5 changes: 2 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()

maven {
name("Fabric")
Expand All @@ -21,9 +23,6 @@ pluginManagement {
name("Cotton")
url("https://server.bbkr.space/artifactory/libs-release")
}

mavenCentral()
gradlePluginPortal()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@
import net.minecraft.world.entity.monster.ZombieVillager;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ZombieVillager.class)
public abstract class MixinZombieVillagerEntity extends Zombie {


public MixinZombieVillagerEntity(EntityType<? extends Zombie> entityType, Level level) {
super(entityType, level);
}

@Shadow
public abstract boolean isConverting();

@Shadow
protected abstract int getConversionProgress();

@Shadow
private int villagerConversionTime;

@Inject(method = "handleEntityEvent", at = @At(value = "RETURN"))
private void syncVillagerData(byte status, CallbackInfo ci) {
if (!Configs.autoSyncEntityData ||
Expand All @@ -32,4 +41,28 @@ private void syncVillagerData(byte status, CallbackInfo ci) {
PcaSyncProtocol.cancelSyncEntity();
}
}

@Inject(method = "tick", at = @At(value = "RETURN"))
private void syncConvertingData(CallbackInfo ci) {
//#if MC > 11904
if (this.level().isClientSide() && this.isAlive() && this.isConverting()) {
//#elseif MC > 11701
//$$ if (this.getLevel().isClientSide() && this.isAlive() && this.isConverting()) {
//#else
//$$ if (this.level.isClientSide() && this.isAlive() && this.isConverting()) {
//#endif
int i = this.getConversionProgress();
this.villagerConversionTime -= i;
if (this.villagerConversionTime <= 0) {
// 如果这里为负,应该是没有同步数据
if (!Configs.autoSyncEntityData ||
Minecraft.getInstance().hasSingleplayerServer() ||
!PcaSyncProtocol.enable) {
return;
}
PcaSyncProtocol.syncEntity(this.getId());
PcaSyncProtocol.cancelSyncEntity();
}
}
}
}

0 comments on commit c96a0bd

Please sign in to comment.