Skip to content

Commit

Permalink
ZombieVillager convert data sync
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Sep 8, 2023
1 parent c82c92d commit 8cbcfbc
Showing 1 changed file with 34 additions and 1 deletion.
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 8cbcfbc

Please sign in to comment.