Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better auto sync data #104

Merged
merged 3 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
}