Files
CatServer/patches/net/minecraft/entity/monster/EntityZombieVillager.java.patch

143 lines
5.7 KiB
Diff

--- ../src-base/minecraft/net/minecraft/entity/monster/EntityZombieVillager.java
+++ ../src-work/minecraft/net/minecraft/entity/monster/EntityZombieVillager.java
@@ -19,6 +19,7 @@
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.potion.PotionEffect;
+import net.minecraft.server.MinecraftServer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
@@ -38,6 +39,8 @@
private int conversionTime;
private UUID converstionStarter;
+ private int lastTick = catserver.server.CatServer.getCurrentTick(); // CatServer - implement realtime
+
public EntityZombieVillager(World worldIn)
{
super(worldIn);
@@ -53,11 +56,14 @@
public void setProfession(int profession)
{
this.dataManager.set(PROFESSION, Integer.valueOf(profession));
+ net.minecraftforge.fml.common.registry.VillagerRegistry.onSetProfession(this, profession);
}
+ //Use Forge Variant below
+ @Deprecated
public int getProfession()
{
- return Math.max(((Integer)this.dataManager.get(PROFESSION)).intValue() % 6, 0);
+ return Math.max(((Integer)this.dataManager.get(PROFESSION)).intValue(), 0);
}
public static void registerFixesZombieVillager(DataFixer fixer)
@@ -69,6 +75,7 @@
{
super.writeEntityToNBT(compound);
compound.setInteger("Profession", this.getProfession());
+ compound.setString("ProfessionName", this.getForgeProfession().getRegistryName().toString());
compound.setInteger("ConversionTime", this.isConverting() ? this.conversionTime : -1);
if (this.converstionStarter != null)
@@ -81,6 +88,12 @@
{
super.readEntityFromNBT(compound);
this.setProfession(compound.getInteger("Profession"));
+ if (compound.hasKey("ProfessionName"))
+ {
+ net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession p = net.minecraftforge.fml.common.registry.ForgeRegistries.VILLAGER_PROFESSIONS.getValue(new ResourceLocation(compound.getString("ProfessionName")));
+ if (p == null) p = net.minecraftforge.fml.common.registry.VillagerRegistry.FARMER;
+ this.setForgeProfession(p);
+ }
if (compound.hasKey("ConversionTime", 99) && compound.getInteger("ConversionTime") > -1)
{
@@ -91,7 +104,7 @@
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
{
- this.setProfession(this.world.rand.nextInt(6));
+ net.minecraftforge.fml.common.registry.VillagerRegistry.setRandomProfession(this, this.world.rand);
return super.onInitialSpawn(difficulty, livingdata);
}
@@ -100,6 +113,11 @@
if (!this.world.isRemote && this.isConverting())
{
int i = this.getConversionProgress();
+ // CraftBukkit start - Use wall time instead of ticks for villager conversion
+ int elapsedTicks = catserver.server.CatServer.getCurrentTick() - this.lastTick; // CatServer - implement realtime
+ this.lastTick = catserver.server.CatServer.getCurrentTick(); // CatServer - implement realtime
+ i *= elapsedTicks;
+ // CraftBukkit end
this.conversionTime -= i;
if (this.conversionTime <= 0)
@@ -135,7 +153,7 @@
}
}
- protected boolean canDespawn()
+ public boolean canDespawn()
{
return !this.isConverting();
}
@@ -175,7 +193,7 @@
{
EntityVillager entityvillager = new EntityVillager(this.world);
entityvillager.copyLocationAndAnglesFrom(this);
- entityvillager.setProfession(this.getProfession());
+ entityvillager.setProfession(this.getForgeProfession());
entityvillager.finalizeMobSpawn(this.world.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null, false);
entityvillager.setLookingForHome();
@@ -193,7 +211,7 @@
entityvillager.setAlwaysRenderNameTag(this.getAlwaysRenderNameTag());
}
- this.world.spawnEntity(entityvillager);
+ this.world.addEntity(entityvillager, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CURED);
if (this.converstionStarter != null)
{
@@ -278,4 +296,37 @@
{
return ItemStack.EMPTY;
}
+
+ /* ======================================== FORGE START =====================================*/
+
+ @Nullable
+ private net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof;
+ public void setForgeProfession(net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof)
+ {
+ this.prof = prof;
+ this.setProfession(net.minecraftforge.fml.common.registry.VillagerRegistry.getId(prof));
+ }
+
+ public net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession getForgeProfession()
+ {
+ if (this.prof == null)
+ {
+ this.prof = net.minecraftforge.fml.common.registry.VillagerRegistry.getById(this.getProfession());
+ if (this.prof == null)
+ return net.minecraftforge.fml.common.registry.VillagerRegistry.FARMER;
+ }
+ return this.prof;
+ }
+
+ @Override
+ public void notifyDataManagerChange(DataParameter<?> key)
+ {
+ super.notifyDataManagerChange(key);
+ if (key.equals(PROFESSION))
+ {
+ net.minecraftforge.fml.common.registry.VillagerRegistry.onSetProfession(this, this.dataManager.get(PROFESSION));
+ }
+ }
+
+ /* ======================================== FORGE END =====================================*/
}