13
0
geforkt von Mirrors/Paper

#1033: Add Villager#zombify

By: Doc <nachito94@msn.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2022-04-15 13:48:55 +10:00
Ursprung 8400a7987a
Commit ef79686997
2 geänderte Dateien mit 34 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -97,21 +97,39 @@
} }
} }
@@ -411,7 +437,12 @@ @@ -411,18 +437,28 @@
} }
EntityVillager entityvillager = (EntityVillager) entityliving; EntityVillager entityvillager = (EntityVillager) entityliving;
- EntityZombieVillager entityzombievillager = (EntityZombieVillager) entityvillager.convertTo(EntityTypes.ZOMBIE_VILLAGER, false); - EntityZombieVillager entityzombievillager = (EntityZombieVillager) entityvillager.convertTo(EntityTypes.ZOMBIE_VILLAGER, false);
+ // CraftBukkit start + // CraftBukkit start
+ EntityZombieVillager entityzombievillager = (EntityZombieVillager) entityvillager.convertTo(EntityTypes.ZOMBIE_VILLAGER, false, EntityTransformEvent.TransformReason.INFECTION, CreatureSpawnEvent.SpawnReason.INFECTION); + zombifyVillager(worldserver, entityvillager, this.blockPosition(), this.isSilent(), false);
+ if (entityzombievillager == null) { + }
+ return; + }
+ }
+ // CraftBukkit end
+ public static EntityZombieVillager zombifyVillager(WorldServer worldserver, EntityVillager entityvillager, net.minecraft.core.BlockPosition blockPosition, boolean silent, boolean custom) {
+ EntityZombieVillager entityzombievillager = (EntityZombieVillager) entityvillager.convertTo(EntityTypes.ZOMBIE_VILLAGER, false, EntityTransformEvent.TransformReason.INFECTION, (custom) ? CreatureSpawnEvent.SpawnReason.CUSTOM : CreatureSpawnEvent.SpawnReason.INFECTION);
+ if (entityzombievillager != null) {
+ // CraftBukkit end
entityzombievillager.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityzombievillager.blockPosition()), EnumMobSpawn.CONVERSION, new EntityZombie.GroupDataZombie(false, true), (NBTTagCompound) null); entityzombievillager.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityzombievillager.blockPosition()), EnumMobSpawn.CONVERSION, new EntityZombie.GroupDataZombie(false, true), (NBTTagCompound) null);
entityzombievillager.setVillagerData(entityvillager.getVillagerData()); entityzombievillager.setVillagerData(entityvillager.getVillagerData());
@@ -473,7 +504,7 @@ entityzombievillager.setGossips((NBTBase) entityvillager.getGossips().store(DynamicOpsNBT.INSTANCE).getValue());
entityzombievillager.setTradeOffers(entityvillager.getOffers().createTag());
entityzombievillager.setVillagerXp(entityvillager.getVillagerXp());
- if (!this.isSilent()) {
- worldserver.levelEvent((EntityHuman) null, 1026, this.blockPosition(), 0);
+ // CraftBukkit start
+ if (!silent) {
+ worldserver.levelEvent((EntityHuman) null, 1026, blockPosition, 0);
}
+ // CraftBukkit end
}
+ return entityzombievillager; // CraftBukkit
}
@Override
@@ -473,7 +509,7 @@
entitychicken1.finalizeSpawn(worldaccess, difficultydamagescaler, EnumMobSpawn.JOCKEY, (GroupDataEntity) null, (NBTTagCompound) null); entitychicken1.finalizeSpawn(worldaccess, difficultydamagescaler, EnumMobSpawn.JOCKEY, (GroupDataEntity) null, (NBTTagCompound) null);
entitychicken1.setChickenJockey(true); entitychicken1.setChickenJockey(true);
this.startRiding(entitychicken1); this.startRiding(entitychicken1);

Datei anzeigen

@ -4,6 +4,8 @@ import com.google.common.base.Preconditions;
import java.util.Locale; import java.util.Locale;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPosition;
import net.minecraft.core.IRegistry; import net.minecraft.core.IRegistry;
import net.minecraft.world.entity.monster.EntityZombie;
import net.minecraft.world.entity.monster.EntityZombieVillager;
import net.minecraft.world.entity.npc.EntityVillager; import net.minecraft.world.entity.npc.EntityVillager;
import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.level.block.BlockBed; import net.minecraft.world.level.block.BlockBed;
@ -14,8 +16,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.ZombieVillager;
import org.bukkit.entity.Villager.Type;
public class CraftVillager extends CraftAbstractVillager implements Villager { public class CraftVillager extends CraftAbstractVillager implements Villager {
@ -121,6 +122,12 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
getHandle().setUnhappy(); getHandle().setUnhappy();
} }
@Override
public ZombieVillager zombify() {
EntityZombieVillager entityzombievillager = EntityZombie.zombifyVillager(getHandle().level.getMinecraftWorld(), getHandle(), getHandle().blockPosition(), isSilent(), true);
return (entityzombievillager != null) ? (ZombieVillager) entityzombievillager.getBukkitEntity() : null;
}
public static Profession nmsToBukkitProfession(VillagerProfession nms) { public static Profession nmsToBukkitProfession(VillagerProfession nms) {
return Profession.valueOf(IRegistry.VILLAGER_PROFESSION.getKey(nms).getPath().toUpperCase(Locale.ROOT)); return Profession.valueOf(IRegistry.VILLAGER_PROFESSION.getKey(nms).getPath().toUpperCase(Locale.ROOT));
} }