From 23234f91273a5abb48923f0ae253e83d82e2a62c Mon Sep 17 00:00:00 2001 From: maxanier Date: Thu, 24 Feb 2022 17:22:22 +0100 Subject: [PATCH 1/3] Start updating MCA integration for MCA Reborn --- build.gradle | 1 - gradle.properties | 9 +- gradle/forge.gradle | 9 +- .../mca/EntityAngryVillagerMCA.java | 165 +++++++++--------- .../mca/EntityConvertedVillagerMCA.java | 147 ++++++++-------- .../mca/EntityVillagerVampirismMCA.java | 130 ++------------ .../mca/EventHandlerMCA.java | 27 +-- .../vampirism_integrations/mca/MCACompat.java | 86 ++++----- .../mca/MCACompatREFERENCE.java | 6 +- 9 files changed, 249 insertions(+), 331 deletions(-) diff --git a/build.gradle b/build.gradle index 870b1b3..f00c21c 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,6 @@ configurations { sourceSets{ main { java{ - exclude '**/mca/*' exclude '**/abyssalcraft/*' exclude '**/toroquest/*' } diff --git a/gradle.properties b/gradle.properties index 437a67c..9bec44b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,11 +4,11 @@ main_version=1 major_version=7 minor_version=0 minecraft_version=1.16.5 -forge_version=36.2.4 +forge_version=36.2.20 mcp_mappings=1.16.5 mcp_channel=official vampirism_mcversion=1.16.5 -vampirism_version=1.8.3 +vampirism_version=1.8.6 bop_fileid=3360574 bop_api_fileid=3360577 hywla_fileid=3033593 @@ -33,9 +33,6 @@ crafttweaker_version=1.16.5:7.1.2.442 mantle_version=1.6.124 guideapi_version=1.16.3-2.2.0 jei_version=1.16.5:7.7.0.104 -#Not currently used -mca_version=6.1.0 -abyssalcraft_version=1.9.12 -ancient_warfare2_version=2.7.0.575 +mca_fileid=3650709 betteranimalsplus_fileid=3286395 betteranimals_fileid=3231449 diff --git a/gradle/forge.gradle b/gradle/forge.gradle index 97bf45a..4506031 100644 --- a/gradle/forge.gradle +++ b/gradle/forge.gradle @@ -167,16 +167,19 @@ dependencies { runtimeOnly fg.deobf("curse.maven:unionlib-367806:"+project.unionlib_fileid) // Diet - https://www.curseforge.com/minecraft/mc-mods/diet - implementation fg.deobf("curse.maven:diet-443570:"+project.diet_fileid) + implementation fg.deobf("curse.maven:diet-443570:" + project.diet_fileid) - implementation fg.deobf("curse.maven:betteranimalsplus-303557:"+project.betteranimalsplus_fileid) + implementation fg.deobf("curse.maven:betteranimalsplus-303557:" + project.betteranimalsplus_fileid) - implementation fg.deobf("curse.maven:betteranimals-287443:"+project.betteranimals_fileid) + implementation fg.deobf("curse.maven:betteranimals-287443:" + project.betteranimals_fileid) // CraftTweaker compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-${project.crafttweaker_version}") //runtimeOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-${project.crafttweaker_version}") // For testing + //MCA + implementation fg.deobf("curse.maven:minecraft-comes-alive-reborn-535291:" + project.mca_fileid) + //Optional runtimeOnly fg.deobf("de.maxanier.guideapi:Guide-API-VP:${project.guideapi_version}") runtimeOnly fg.deobf("mezz.jei:jei-${project.jei_version}") //Full for runtime diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityAngryVillagerMCA.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityAngryVillagerMCA.java index c5ec3b0..a54b4ef 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityAngryVillagerMCA.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityAngryVillagerMCA.java @@ -1,26 +1,36 @@ package de.teamlapen.vampirism_integrations.mca; +import de.teamlapen.lib.lib.util.UtilLib; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism.api.entity.IAggressiveVillager; import de.teamlapen.vampirism.api.entity.factions.IFaction; -import de.teamlapen.vampirism.api.world.IVampirismVillage; -import de.teamlapen.vampirism.entity.ai.EntityAIDefendVillage; -import de.teamlapen.vampirism.entity.ai.EntityAIMoveThroughVillageCustom; -import mca.core.minecraft.ProfessionsMCA; -import mca.entity.EntityVillagerMCA; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityCreature; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.ai.*; -import net.minecraft.entity.player.EntityPlayer; +import de.teamlapen.vampirism.api.world.ICaptureAttributes; +import de.teamlapen.vampirism.core.ModItems; +import de.teamlapen.vampirism.entity.goals.DefendVillageGoal; +import mca.entity.VillagerEntityMCA; +import mca.entity.ai.ProfessionsMCA; +import mca.entity.ai.relationship.Gender; +import net.minecraft.entity.*; +import net.minecraft.entity.ai.goal.HurtByTargetGoal; +import net.minecraft.entity.ai.goal.MeleeAttackGoal; +import net.minecraft.entity.ai.goal.MoveThroughVillageGoal; +import net.minecraft.entity.ai.goal.NearestAttackableTargetGoal; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumHand; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Hand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.IServerWorld; import net.minecraft.world.World; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.registries.ObjectHolder; +import javax.annotation.Nonnull; import javax.annotation.Nullable; /** @@ -29,64 +39,59 @@ */ public class EntityAngryVillagerMCA extends EntityVillagerVampirismMCA implements IAggressiveVillager { - private ItemStack pitchforkStack; - private AxisAlignedBB area; - - - public EntityAngryVillagerMCA(World world) { - super(world); - pitchforkStack = new ItemStack(MCACompatREFERENCE.pitchfork); - } - - @Override - public boolean attackEntityAsMob(Entity entity) { - this.swingArm(getActiveHand()); - return super.attackEntityAsMob(entity); - } + @ObjectHolder("vampirism_integrations:mca_angry_villager_male") + private static final EntityType angry_villager_male = UtilLib.getNull(); + @ObjectHolder("vampirism_integrations:mca_angry_villager_female") + private static final EntityType angry_villager_female = UtilLib.getNull(); @Nullable - public static EntityAngryVillagerMCA makeAngry(EntityVillagerMCA villager) { - if (villager.getProfessionForge() == ProfessionsMCA.guard || villager.getProfessionForge() == ProfessionsMCA.bandit || villager.get(EntityVillagerMCA.IS_INFECTED)) { + public static EntityAngryVillagerMCA makeAngry(VillagerEntityMCA villager) { + if (villager.getProfession() == ProfessionsMCA.GUARD || villager.getProfession() == ProfessionsMCA.OUTLAW || villager.isInfected()) { return null;//Don't make guards or infected villagers angry } - EntityAngryVillagerMCA angry = new EntityAngryVillagerMCA(villager.getEntityWorld()); - NBTTagCompound tag = new NBTTagCompound(); - villager.writeToNBT(tag); - angry.readFromNBT(tag); - angry.setUniqueId(MathHelper.getRandomUUID(villager.getRNG())); + EntityAngryVillagerMCA angry = new EntityAngryVillagerMCA(villager.getGenetics().getGender() == Gender.FEMALE ? angry_villager_female : angry_villager_male, villager.level, villager.getGenetics().getGender()); + CompoundNBT tag = new CompoundNBT(); + villager.saveWithoutId(tag); + angry.load(tag); + angry.setUUID(MathHelper.createInsecureUUID(villager.getRandom())); return angry; } - @Override - public ItemStack getHeldItem(EnumHand hand) { - return pitchforkStack; + @Nullable + private ICaptureAttributes villageAttributes; + + + public EntityAngryVillagerMCA(EntityType type, World w, Gender gender) { + super(type, w, gender); } @Override - public void attackVillage(AxisAlignedBB area) { + public void attackVillage(ICaptureAttributes villageAttributes) { + this.villageAttributes = villageAttributes; } @Override - public ItemStack getHeldItemMainhand() { - return pitchforkStack; + public void defendVillage(ICaptureAttributes villageAttributes) { + this.villageAttributes = villageAttributes; } @Override - public void defendVillage(AxisAlignedBB area) { - this.area = area; + public ILivingEntityData finalizeSpawn(@Nonnull IServerWorld worldIn, @Nonnull DifficultyInstance difficultyIn, @Nonnull SpawnReason reason, @Nullable ILivingEntityData spawnDataIn, @Nullable CompoundNBT dataTag) { + ILivingEntityData data = super.finalizeSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag); + this.setItemSlot(EquipmentSlotType.MAINHAND, new ItemStack(ModItems.pitchfork)); + return data; } @Nullable @Override - public IVampirismVillage getCurrentFriendlyVillage() { - return this.vampirismVillage != null ? this.vampirismVillage.getControllingFaction() == VReference.HUNTER_FACTION ? this.vampirismVillage : null : null; + public ICaptureAttributes getCaptureInfo() { + return villageAttributes; } - @Nullable @Override - public AxisAlignedBB getTargetVillageArea() { - return area; + public IFaction getFaction() { + return VReference.HUNTER_FACTION; } @Override @@ -95,59 +100,59 @@ public boolean isAttackingVillage() { } @Override - public void stopVillageAttackDefense() { - EntityVillagerMCA mca = new EntityVillagerMCA(this.getEntityWorld()); - NBTTagCompound nbt = new NBTTagCompound(); - this.writeToNBT(nbt); - mca.readFromNBT(nbt); - this.world.spawnEntity(mca); - this.setDead(); + public LivingEntity getRepresentingEntity() { + return this; } + @Nullable @Override - public void readEntityFromNBT(NBTTagCompound nbt) { - super.readEntityFromNBT(nbt); - applySpecialAITasks(); + public AxisAlignedBB getTargetVillageArea() { + return villageAttributes == null ? null : villageAttributes.getVillageArea(); } - protected void applySpecialAITasks() { - this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); - this.targetTasks.addTask(2, new EntityAINearestAttackableTarget<>(this, EntityPlayer.class, 10, true, false, VampirismAPI.factionRegistry().getPredicate(getFaction(), true, false, false, false, null))); - this.targetTasks.addTask(3, new EntityAIDefendVillage<>(this)); - this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityCreature.class, 5, true, false, VampirismAPI.factionRegistry().getPredicate(getFaction(), false, true, false, false, null)) { - - @Override - protected double getTargetDistance() { - return super.getTargetDistance() / 2; - } - }); + @Override + public boolean isDefendingVillage() { + return villageAttributes != null; } - @Override - public IFaction getFaction() { - return VReference.HUNTER_FACTION; + public void refreshBrain(@Nonnull ServerWorld serverWorldIn) { } @Override - public EntityLivingBase getRepresentingEntity() { - return this; + public void stopVillageAttackDefense() { + VillagerEntityMCA villager = this.getGenetics().getGender().getVillagerType().create(this.level); + assert villager != null; + this.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY); + CompoundNBT nbt = new CompoundNBT(); + this.saveWithoutId(nbt); + villager.load(nbt); + villager.setUUID(MathHelper.createInsecureUUID(this.random)); + UtilLib.replaceEntity(this, villager); } @Override - public void writeEntityToNBT(NBTTagCompound nbt) { - super.writeEntityToNBT(nbt); + protected ITextComponent getTypeName() { + return this.getType().getDescription(); //Don't use profession as part of the translation key } @Override - protected void initEntityAI() { - super.initEntityAI(); - this.tasks.taskEntries.removeIf(entry -> entry.action instanceof EntityAITradePlayer || entry.action instanceof EntityAILookAtTradePlayer || entry.action instanceof EntityAIVillagerMate || entry.action instanceof EntityAIFollowGolem); - this.tasks.addTask(6, new EntityAIAttackMelee(this, 0.6, false)); - this.tasks.addTask(8, new EntityAIMoveThroughVillageCustom(this, 0.55, false, 400)); + protected void registerGoals() { + super.registerGoals(); + this.goalSelector.addGoal(6, new MeleeAttackGoal(this, 0.6, false)); + this.goalSelector.addGoal(8, new MoveThroughVillageGoal(this, 0.55, false, 400, () -> true)); - applySpecialAITasks(); + this.targetSelector.addGoal(1, new HurtByTargetGoal(this)); + this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, 5, true, false, VampirismAPI.factionRegistry().getPredicate(getFaction(), true, false, false, false, null))); + this.targetSelector.addGoal(3, new DefendVillageGoal<>(this)); + this.targetSelector.addGoal(4, new NearestAttackableTargetGoal(this, CreatureEntity.class, 5, true, false, VampirismAPI.factionRegistry().getPredicate(getFaction(), false, true, false, false, null)) { + @Override + protected double getFollowDistance() { + return super.getFollowDistance() / 2; + } + }); } + } diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityConvertedVillagerMCA.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityConvertedVillagerMCA.java index bea1600..1792917 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityConvertedVillagerMCA.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityConvertedVillagerMCA.java @@ -1,28 +1,32 @@ package de.teamlapen.vampirism_integrations.mca; -import com.google.common.base.Predicates; +import com.mojang.serialization.Dynamic; +import de.teamlapen.lib.lib.util.UtilLib; import de.teamlapen.vampirism.api.EnumStrength; import de.teamlapen.vampirism.api.VReference; -import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism.api.entity.convertible.IConvertedCreature; import de.teamlapen.vampirism.api.entity.convertible.IConvertingHandler; import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.player.vampire.IBloodStats; +import de.teamlapen.vampirism.core.ModVillage; import de.teamlapen.vampirism.entity.DamageHandler; -import de.teamlapen.vampirism.entity.ai.EntityAIMoveIndoorsDay; -import de.teamlapen.vampirism.entity.ai.VampireAIBiteNearbyEntity; -import de.teamlapen.vampirism.entity.ai.VampireAIFleeSun; -import de.teamlapen.vampirism.entity.ai.VampireAIMoveToBiteable; +import de.teamlapen.vampirism.player.vampire.VampirePlayer; import de.teamlapen.vampirism.util.Helper; -import mca.entity.EntityVillagerMCA; -import net.minecraft.entity.EntityCreature; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.ai.*; -import net.minecraft.init.MobEffects; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.PotionEffect; +import mca.entity.VillagerEntityMCA; +import mca.entity.ai.relationship.Gender; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.brain.Brain; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.potion.EffectInstance; +import net.minecraft.potion.Effects; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.IWorld; import net.minecraft.world.World; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.registries.ObjectHolder; import javax.annotation.Nonnull; @@ -30,49 +34,58 @@ * Vampire version of MCA's villager * Tries to suck blood during the night */ -public class EntityConvertedVillagerMCA extends EntityVillagerVampirismMCA implements IConvertedCreature { +public class EntityConvertedVillagerMCA extends EntityVillagerVampirismMCA implements IConvertedCreature { + + @ObjectHolder("vampirism_integrations:mca_converted_villager_male") + public static final EntityType converted_villager_male = UtilLib.getNull(); + @ObjectHolder("vampirism_integrations:mca_converted_villager_female") + public static final EntityType converted_villager_female = UtilLib.getNull(); private EnumStrength garlicCache; private boolean sundamageCache; private int bloodTimer = 0; - public EntityConvertedVillagerMCA(World world) { - super(world); + public EntityConvertedVillagerMCA(EntityType type, World w, Gender gender) { + super(type, w, gender); garlicCache = EnumStrength.NONE; } - - + public void adjustBrainGoals(@Nonnull Brain brain) { + brain.setSchedule(ModVillage.converted_default); + brain.updateActivityFromSchedule(this.level.getDayTime(), this.level.getGameTime()); + } @Override - public void onLivingUpdate() { - if (this.ticksExisted % MCACompatREFERENCE.REFRESH_GARLIC_TICKS == 1) { - isGettingGarlicDamage(true); + public void aiStep() { + if (this.tickCount % MCACompatREFERENCE.REFRESH_GARLIC_TICKS == 1) { + isGettingGarlicDamage(level, true); } - if (this.ticksExisted % MCACompatREFERENCE.REFRESH_SUNDAMAGE_TICKS == 2) { - isGettingSundamage(true); + if (this.tickCount % MCACompatREFERENCE.REFRESH_SUNDAMAGE_TICKS == 2) { + isGettingSundamage(level, true); } - if (!world.isRemote) { - if (isGettingSundamage() && ticksExisted % 40 == 11) { - this.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 42)); - this.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 42)); - + if (!level.isClientSide) { + if (isGettingSundamage(level) && tickCount % 40 == 11) { + this.addEffect(new EffectInstance(Effects.WEAKNESS, 42)); } - if (isGettingGarlicDamage() != EnumStrength.NONE) { - DamageHandler.affectVampireGarlicAmbient(this, isGettingGarlicDamage(), this.ticksExisted); + if (isGettingGarlicDamage(level) != EnumStrength.NONE) { + DamageHandler.affectVampireGarlicAmbient(this, isGettingGarlicDamage(level), this.tickCount); } } - super.onLivingUpdate(); + super.aiStep(); bloodTimer++; } @Override - public void drinkBlood(int amt, float saturationMod, boolean useRemaining) { - this.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, amt * 20)); - bloodTimer = -1200 - rand.nextInt(1200); + public boolean doHurtTarget(Entity entity) { + if (!level.isClientSide && wantsBlood() && entity instanceof PlayerEntity && !Helper.isHunter(entity) && !UtilLib.canReallySee((LivingEntity) entity, this, true)) { + int amt = VampirePlayer.getOpt((PlayerEntity) entity).map(vampire -> vampire.onBite(this)).orElse(0); + drinkBlood(amt, IBloodStats.MEDIUM_SATURATION); + return true; + } + return super.doHurtTarget(entity); } @Override @@ -81,46 +94,36 @@ public boolean doesResistGarlic(EnumStrength strength) { } @Override - protected void initEntityAI() { - super.initEntityAI(); - - this.tasks.taskEntries.removeIf(entry -> entry.action instanceof EntityAIMoveIndoors || entry.action instanceof EntityAIVillagerMate || entry.action instanceof EntityAIFollowGolem); - - tasks.addTask(0, new EntityAIRestrictSun(this)); - tasks.addTask(1, new EntityAIAvoidEntity<>(this, EntityCreature.class, VampirismAPI.factionRegistry().getPredicate(getFaction(), true, true, false, false, VReference.HUNTER_FACTION), 10, 0.45F, 0.55F)); - tasks.addTask(2, new EntityAIMoveIndoorsDay(this)); - tasks.addTask(5, new VampireAIFleeSun(this, 0.6F, true)); - tasks.addTask(6, new EntityAIAttackMelee(this, 0.6F, false)); - tasks.addTask(7, new VampireAIBiteNearbyEntity(this)); - tasks.addTask(9, new VampireAIMoveToBiteable(this, 0.55F)); - - - this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); - + public void drinkBlood(int amt, float saturationMod, boolean useRemaining) { + this.addEffect(new EffectInstance(Effects.REGENERATION, amt * 20)); + bloodTimer = -1200 - random.nextInt(1200); } @Override - public void readEntityFromNBT(NBTTagCompound nbt) { - super.readEntityFromNBT(nbt); - bloodTimer = nbt.hasKey("vamp_converted_bloodtimer") ? nbt.getInteger("vamp_converted_bloodtimer") : 0; - + public LivingEntity getRepresentingEntity() { + return this; } @Nonnull @Override - public EnumStrength isGettingGarlicDamage(boolean forceRefresh) { + public EnumStrength isGettingGarlicDamage(IWorld iWorld, boolean forceRefresh) { if (forceRefresh) { - garlicCache = Helper.getGarlicStrength(this); + garlicCache = Helper.getGarlicStrength(this, iWorld); } return garlicCache; } @Override - public boolean isGettingSundamage(boolean forceRefresh) { + public boolean isGettingSundamage(IWorld iWorld, boolean forceRefresh) { if (!forceRefresh) return sundamageCache; - return (sundamageCache = Helper.gettingSundamge(this)); + return (sundamageCache = Helper.gettingSundamge(this, iWorld, this.level.getProfiler())); } + @Override + public void refreshBrain(ServerWorld world) { + super.refreshBrain(world); + adjustBrainGoals(getMCABrain()); + } @Override public boolean isIgnoringSundamage() { @@ -143,25 +146,21 @@ public boolean wantsBlood() { } @Override - public void writeEntityToNBT(NBTTagCompound nbt) { - super.writeEntityToNBT(nbt); - nbt.setInteger("vamp_converted_bloodtimer", bloodTimer); - } - - @Override - public EntityLivingBase getRepresentingEntity() { - return this; + protected Brain makeBrain(Dynamic dynamic) { + Brain b = super.makeBrain(dynamic); + adjustBrainGoals(b); + return b; } - public static class ConvertingHandler implements IConvertingHandler { + public static class ConvertingHandler implements IConvertingHandler { @Override - public IConvertedCreature createFrom(EntityVillagerMCA entity) { - NBTTagCompound nbt = new NBTTagCompound(); - entity.writeToNBT(nbt); - EntityConvertedVillagerMCA converted = new EntityConvertedVillagerMCA(entity.world); - converted.readFromNBT(nbt); - converted.setUniqueId(MathHelper.getRandomUUID(converted.rand)); + public IConvertedCreature createFrom(VillagerEntityMCA entity) { + CompoundNBT nbt = new CompoundNBT(); + entity.saveWithoutId(nbt); + EntityConvertedVillagerMCA converted = new EntityConvertedVillagerMCA(entity.getGenetics().getGender() == Gender.FEMALE ? converted_villager_female : converted_villager_male, entity.level, entity.getGenetics().getGender()); + converted.load(nbt); + converted.setUUID(MathHelper.createInsecureUUID(converted.random)); return converted; } } diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityVillagerVampirismMCA.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityVillagerVampirismMCA.java index 5377a29..f881294 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityVillagerVampirismMCA.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityVillagerVampirismMCA.java @@ -1,139 +1,41 @@ package de.teamlapen.vampirism_integrations.mca; -import com.google.common.base.Optional; -import de.teamlapen.vampirism.api.VampirismAPI; -import de.teamlapen.vampirism.api.world.IVampirismVillage; -import mca.entity.EntityVillagerMCA; -import mca.enums.EnumGender; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.SharedMonsterAttributes; -import net.minecraft.util.DamageSource; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.village.Village; -import net.minecraft.world.EnumDifficulty; +import mca.entity.VillagerEntityMCA; +import mca.entity.ai.relationship.Gender; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnReason; +import net.minecraft.world.Difficulty; +import net.minecraft.world.IWorld; import net.minecraft.world.World; -import net.minecraftforge.fml.common.registry.VillagerRegistry; - -import javax.annotation.Nullable; /** * Vampirism's basic extension of MCA's villager */ -abstract class EntityVillagerVampirismMCA extends EntityVillagerMCA { - private static @Nullable - IVampirismVillage getNearestVillage(World w, BlockPos pos, int r) { - Village v = w.villageCollection.getNearestVillage(pos, r); - if (v != null) { - return VampirismAPI.getVampirismVillage(v); - } - return null; - } +abstract class EntityVillagerVampirismMCA extends VillagerEntityMCA { - private boolean peaceful = false; - @Nullable - IVampirismVillage vampirismVillage; - /** - * A timer which reaches 0 every 70 to 120 ticks - */ - private int randomTickDivider; + private final boolean peaceful = false; - public EntityVillagerVampirismMCA(World worldIn) { - super(worldIn); - } - public EntityVillagerVampirismMCA(World worldIn, Optional profession, Optional gender) { - super(worldIn, profession, gender); + public EntityVillagerVampirismMCA(EntityType type, World w, Gender gender) { + super((EntityType) type, w, gender); } @Override - public boolean attackEntityAsMob(Entity entity) { - float f = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); - int i = 0; - - if (entity instanceof EntityLivingBase) { - f += EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase) entity).getCreatureAttribute()); - i += EnchantmentHelper.getKnockbackModifier(this); - } - - boolean flag = entity.attackEntityFrom(DamageSource.causeMobDamage(this), f); - - if (flag) { - if (i > 0) { - entity.addVelocity(-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F) * (float) i * 0.5F, 0.1D, MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F) * (float) i * 0.5F); - this.motionX *= 0.6D; - this.motionZ *= 0.6D; - } - - int j = EnchantmentHelper.getFireAspectModifier(this); - - if (j > 0) { - entity.setFire(j * 4); - } - - this.applyEnchantments(this, entity); - - } - - - return flag; + public boolean checkSpawnRules(IWorld worldIn, SpawnReason spawnReasonIn) { + return (peaceful || worldIn.getDifficulty() != Difficulty.PEACEFUL) && super.checkSpawnRules(worldIn, spawnReasonIn); } - @Override - public boolean attackEntityFrom(DamageSource src, float amount) { - if (this.isEntityInvulnerable(src)) { - return false; - } else if (super.attackEntityFrom(src, amount)) { - Entity entity = src.getTrueSource(); - if (entity instanceof EntityLivingBase) { - this.setAttackTarget((EntityLivingBase) entity); - } - return true; - } - return false; - } - - @Override - public boolean getCanSpawnHere() { - return (peaceful || this.world.getDifficulty() != EnumDifficulty.PEACEFUL) && super.getCanSpawnHere(); - } - - - @Override - public void onLivingUpdate() { - this.updateArmSwingProgress(); - super.onLivingUpdate(); - } @Override - public void onUpdate() { - super.onUpdate(); + public void tick() { + super.tick(); - if (!this.world.isRemote && !peaceful && this.world.getDifficulty() == EnumDifficulty.PEACEFUL) { - this.setDead(); + if (!this.level.isClientSide && !peaceful && this.level.getDifficulty() == Difficulty.PEACEFUL) { + this.remove(); } } - @Override - protected void applyEntityAttributes() { - super.applyEntityAttributes(); - if (this.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.ATTACK_DAMAGE) == null) { - this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); - - } - } - @Override - protected void updateAITasks() { - super.updateAITasks(); - if (--this.randomTickDivider <= 0) { - this.randomTickDivider = 70 + rand.nextInt(50); - this.vampirismVillage = getNearestVillage(world, getPosition(), 32); - } - - } } diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/EventHandlerMCA.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/EventHandlerMCA.java index dcd42bf..ebe424f 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/EventHandlerMCA.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/EventHandlerMCA.java @@ -1,36 +1,41 @@ package de.teamlapen.vampirism_integrations.mca; -import com.google.common.base.Optional; +import de.teamlapen.lib.lib.util.UtilLib; import de.teamlapen.vampirism.api.event.VampirismVillageEvent; import de.teamlapen.vampirism_integrations.VampirismIntegrationsMod; -import mca.entity.EntityVillagerMCA; -import net.minecraftforge.fml.common.eventhandler.Event; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import mca.entity.VillagerEntityMCA; +import mca.entity.ai.relationship.Gender; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.SubscribeEvent; + class EventHandlerMCA { @SubscribeEvent public void onCreateAggressiveVillager(VampirismVillageEvent.MakeAggressive event) { try { - if (event.getOldVillager() instanceof EntityVillagerMCA) { - EntityAngryVillagerMCA angry = EntityAngryVillagerMCA.makeAngry((EntityVillagerMCA) event.getOldVillager()); - event.setAgressiveVillager(angry); //Can be null to prevent conversion + if (event.getOldVillager() instanceof VillagerEntityMCA) { + EntityAngryVillagerMCA angry = EntityAngryVillagerMCA.makeAngry((VillagerEntityMCA) event.getOldVillager()); event.setCanceled(true); + UtilLib.replaceEntity(event.getOldVillager(), angry); } } catch (Exception e) { - VampirismIntegrationsMod.log.e("MCA_Events", e, "Failed to make villager aggressive"); + VampirismIntegrationsMod.LOGGER.error("Failed to make villager aggressive", e); } } @SubscribeEvent public void onSpawnNewVillager(VampirismVillageEvent.SpawnNewVillager event) { try { - EntityVillagerMCA villager = new EntityVillagerMCA(event.getSeedVillager().getEntityWorld(), Optional.absent(), Optional.absent()); - villager.copyLocationAndAnglesFrom(event.getSeedVillager()); + Gender g = Gender.getRandom(); + VillagerEntityMCA villager = new VillagerEntityMCA(g.getVillagerType(), event.getWorld(), g); + if (event.getOldEntity() != null) { + villager.copyPosition(event.getOldEntity()); + } event.setNewVillager(villager); event.setResult(Event.Result.ALLOW); } catch (Exception e) { - VampirismIntegrationsMod.log.e("MCA_Events", e, "Failed to spawn new MCA villager"); + VampirismIntegrationsMod.LOGGER.error("Failed to spawn new MCA villager", e); } } diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java index 97a9160..31343d3 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java @@ -1,81 +1,89 @@ package de.teamlapen.vampirism_integrations.mca; -import de.teamlapen.vampirism_integrations.IModCompat; +import de.teamlapen.lib.lib.util.IInitListener; +import de.teamlapen.lib.lib.util.IModCompat; +import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; -import de.teamlapen.vampirism_integrations.VampirismIntegrationsMod; +import de.teamlapen.vampirism_integrations.IInterModeEnqueue; import de.teamlapen.vampirism_integrations.mca.client.ClientProxy; import de.teamlapen.vampirism_integrations.mca.client.OverlayAssignmentLoader; import de.teamlapen.vampirism_integrations.util.REFERENCE; -import mca.entity.EntityVillagerMCA; -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.TextComponentString; -import net.minecraftforge.client.ClientCommandHandler; +import mca.entity.EntitiesMCA; +import mca.entity.ai.relationship.Gender; +import net.minecraft.entity.EntityType; +import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.ModContainer; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLStateEvent; -import net.minecraftforge.fml.common.registry.EntityRegistry; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; +import net.minecraftforge.fml.event.lifecycle.ParallelDispatchEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import javax.annotation.Nullable; -import java.io.*; -import java.util.Enumeration; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; -import java.util.zip.ZipOutputStream; -public class MCACompat implements IModCompat { +public class MCACompat implements IModCompat, IInterModeEnqueue { - public static final String CONVERTED_VILLAGER_ID = "villagermcaconverted"; - public static final String ANGRY_VILLAGER_ID = "villagermcaangry"; public static final String ID = "mca"; - protected static final String VILLAGER_ID = "villagermca"; - private int villager_blood_value; + public static void registerEntities(RegistryEvent.Register> event) { + if (ModList.get().isLoaded(ID)) { //TODO is this a good idea? + event.getRegistry().register(MCACompat.prepareEntity((type, level) -> new EntityConvertedVillagerMCA(type, level, Gender.MALE), "mca_converted_villager_male")); + event.getRegistry().register(MCACompat.prepareEntity((type, level) -> new EntityConvertedVillagerMCA(type, level, Gender.FEMALE), "mca_converted_villager_female")); + event.getRegistry().register(MCACompat.prepareEntity((type, level) -> new EntityAngryVillagerMCA(type, level, Gender.MALE), "mca_angry_villager_male")); + event.getRegistry().register(MCACompat.prepareEntity((type, level) -> new EntityAngryVillagerMCA(type, level, Gender.FEMALE), "mca_angry_villager_female")); + } + } + private static EntityType prepareEntity(EntityType.IFactory factory, String id) { + EntityType.Builder builder = EntityType.Builder.of(factory, VReference.VAMPIRE_CREATURE_TYPE).sized(0.6F, 1.95F).setTrackingRange(80).setUpdateInterval(1).setShouldReceiveVelocityUpdates(true); + EntityType entry = builder.build(REFERENCE.MODID + ":" + id); + entry.setRegistryName(REFERENCE.MODID, id); + return entry; + } @Override public String getModID() { return ID; } + public MCACompat() { + FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(EntityType.class, MCACompat::registerEntities); + } + + @Override + public void buildConfig(ForgeConfigSpec.Builder builder) { + + } + + @Override + public void enqueueIMC(InterModEnqueueEvent event) { + VampirismAPI.entityRegistry().addConvertible(EntitiesMCA.FEMALE_VILLAGER, null, new EntityConvertedVillagerMCA.ConvertingHandler()); + VampirismAPI.entityRegistry().addConvertible(EntitiesMCA.MALE_VILLAGER, null, new EntityConvertedVillagerMCA.ConvertingHandler()); + } + @Nullable @Override public String getAcceptedVersionRange() { - return "[1.12.2-6.1.0,)"; + return "[7.0.8,)"; } @Override - public void loadConfigs(Configuration config, ConfigCategory category) { - villager_blood_value = config.getInt("villager_blood_value", category.getName(), 15, 1, 1000, ""); + public void onInitStep(IInitListener.Step step, ParallelDispatchEvent event) { + } @Override public void onInitStep(Step step, FMLStateEvent event) { if (step == Step.PRE_INIT) { - VampirismAPI.entityRegistry().addBloodValue(new ResourceLocation(ID, VILLAGER_ID), villager_blood_value); - VampirismAPI.entityRegistry().addConvertible(EntityVillagerMCA.class, null, new EntityConvertedVillagerMCA.ConvertingHandler()); + if (FMLCommonHandler.instance().getSide().isClient()) { ClientProxy.registerRenderer(); OverlayAssignmentLoader.init(((FMLPreInitializationEvent) event).getModConfigurationDirectory()); OverlayAssignmentLoader.registerSaveCommand(); } MinecraftForge.EVENT_BUS.register(new EventHandlerMCA()); - } else if (step == Step.INIT) { - int baseEntityId = 0; - EntityRegistry.registerModEntity(new ResourceLocation(REFERENCE.MODID, CONVERTED_VILLAGER_ID), EntityConvertedVillagerMCA.class, EntityConvertedVillagerMCA.class.getSimpleName(), baseEntityId++, VampirismIntegrationsMod.instance, 50, 2, true); - EntityRegistry.registerModEntity(new ResourceLocation(REFERENCE.MODID, ANGRY_VILLAGER_ID), EntityAngryVillagerMCA.class, EntityAngryVillagerMCA.class.getSimpleName(), baseEntityId++, VampirismIntegrationsMod.instance, 50, 2, true); - } } } diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompatREFERENCE.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompatREFERENCE.java index 076cadb..46387cd 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompatREFERENCE.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompatREFERENCE.java @@ -2,14 +2,14 @@ import net.minecraft.item.Item; import net.minecraft.util.SoundEvent; -import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraftforge.registries.ObjectHolder; public class MCACompatREFERENCE { - @GameRegistry.ObjectHolder("vampirism:player.bite") + @ObjectHolder("vampirism:player.bite") static final SoundEvent player_bite = null; - @GameRegistry.ObjectHolder("vampirism:pitchfork") + @ObjectHolder("vampirism:pitchfork") static final Item pitchfork = null; /** From 67a21c0caae77f459b4520c540017e2dff626cbf Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Tue, 14 Jun 2022 16:07:40 +0200 Subject: [PATCH 2/3] update mca entities --- gradle.properties | 6 +- gradle/forge.gradle | 7 +- .../VampirismIntegrationsMod.java | 2 + .../mca/EntityAngryVillagerMCA.java | 4 +- .../vampirism_integrations/mca/MCACompat.java | 32 +++-- .../mca/MCACompatREFERENCE.java | 5 - .../mca/client/ClientProxy.java | 10 +- .../mca/client/LayerVampireFace.java | 134 ++++++++---------- .../mca/client/OverlayAssignmentLoader.java | 69 ++++----- .../client/RenderVillagerMCAConverted.java | 24 ++-- 10 files changed, 141 insertions(+), 152 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9bec44b..4a095a3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,11 +4,11 @@ main_version=1 major_version=7 minor_version=0 minecraft_version=1.16.5 -forge_version=36.2.20 +forge_version=36.2.26 mcp_mappings=1.16.5 mcp_channel=official vampirism_mcversion=1.16.5 -vampirism_version=1.8.6 +vampirism_version=1.8.9 bop_fileid=3360574 bop_api_fileid=3360577 hywla_fileid=3033593 @@ -24,7 +24,7 @@ structurize_version=0.13.177-ALPHA evilcraft_fileid=3525654 cyclopscore_fileid=3517568 tough_as_nails_fileid=3430873 -survive_fileid=3416821 +survive_fileid=3655901 unionlib_fileid=3405963 diet_fileid=3525299 tconstruct_version=3.2.1.296 diff --git a/gradle/forge.gradle b/gradle/forge.gradle index 4506031..9b7fa34 100644 --- a/gradle/forge.gradle +++ b/gradle/forge.gradle @@ -52,10 +52,7 @@ repositories { name = "LocalForge" url = "../../MinecraftForge/repo/" } - maven { - name = "Local2" - url = "../../../.m2/repository" - } + mavenLocal() maven { url = 'https://maven.blamejared.com' @@ -162,7 +159,7 @@ dependencies { runtimeOnly fg.deobf("slimeknights.mantle:Mantle:1.16.5-"+project.mantle_version) // Survive - https://www.curseforge.com/minecraft/mc-mods/survive - implementation fg.deobf("curse.maven:survive-367337:"+project.survive_fileid) + compileOnly fg.deobf("curse.maven:survive-367337:"+project.survive_fileid) // UnionLib - https://www.curseforge.com/minecraft/mc-mods/unionlib runtimeOnly fg.deobf("curse.maven:unionlib-367806:"+project.unionlib_fileid) diff --git a/src/main/java/de/teamlapen/vampirism_integrations/VampirismIntegrationsMod.java b/src/main/java/de/teamlapen/vampirism_integrations/VampirismIntegrationsMod.java index 7b51a2e..aa22410 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/VampirismIntegrationsMod.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/VampirismIntegrationsMod.java @@ -12,6 +12,7 @@ import de.teamlapen.vampirism_integrations.crafttweaker.CrafttweakerCompat; import de.teamlapen.vampirism_integrations.diet.DietCompat; import de.teamlapen.vampirism_integrations.evilcraft.EvilCraftCompat; +import de.teamlapen.vampirism_integrations.mca.MCACompat; import de.teamlapen.vampirism_integrations.survive.SurviveCompat; import de.teamlapen.vampirism_integrations.tan.TANCompat; import de.teamlapen.vampirism_integrations.tconstruct.TConstructCompat; @@ -73,6 +74,7 @@ public VampirismIntegrationsMod() { compatLoader.addModCompat(new BetterAnimalsPlusCompat()); compatLoader.addModCompat(new BetterAnimalsCompat()); compatLoader.addModCompat(new CrafttweakerCompat()); + compatLoader.addModCompat(new MCACompat()); FMLJavaModLoadingContext.get().getModEventBus().register(this); MinecraftForge.EVENT_BUS.addListener(this::onCommandRegister); MinecraftForge.EVENT_BUS.register(new EventHandler()); diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityAngryVillagerMCA.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityAngryVillagerMCA.java index a54b4ef..db9b134 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityAngryVillagerMCA.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/EntityAngryVillagerMCA.java @@ -40,9 +40,9 @@ public class EntityAngryVillagerMCA extends EntityVillagerVampirismMCA implements IAggressiveVillager { @ObjectHolder("vampirism_integrations:mca_angry_villager_male") - private static final EntityType angry_villager_male = UtilLib.getNull(); + public static final EntityType angry_villager_male = UtilLib.getNull(); @ObjectHolder("vampirism_integrations:mca_angry_villager_female") - private static final EntityType angry_villager_female = UtilLib.getNull(); + public static final EntityType angry_villager_female = UtilLib.getNull(); @Nullable public static EntityAngryVillagerMCA makeAngry(VillagerEntityMCA villager) { diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java index 31343d3..f76e6a6 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java @@ -11,9 +11,12 @@ import mca.entity.EntitiesMCA; import mca.entity.ai.relationship.Gender; import net.minecraft.entity.EntityType; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.event.entity.EntityAttributeCreationEvent; +import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.event.lifecycle.ParallelDispatchEvent; @@ -35,6 +38,15 @@ public static void registerEntities(RegistryEvent.Register> event) } } + public static void registerEntityTypeAttributes(EntityAttributeCreationEvent event) { + if (ModList.get().isLoaded(ID)) { //TODO is this a good idea? + event.put(EntityAngryVillagerMCA.angry_villager_male, EntityAngryVillagerMCA.createVillagerAttributes().build()); + event.put(EntityAngryVillagerMCA.angry_villager_female, EntityAngryVillagerMCA.createVillagerAttributes().build()); + event.put(EntityConvertedVillagerMCA.converted_villager_male, EntityConvertedVillagerMCA.createVillagerAttributes().build()); + event.put(EntityConvertedVillagerMCA.converted_villager_female, EntityConvertedVillagerMCA.createVillagerAttributes().build()); + } + } + private static EntityType prepareEntity(EntityType.IFactory factory, String id) { EntityType.Builder builder = EntityType.Builder.of(factory, VReference.VAMPIRE_CREATURE_TYPE).sized(0.6F, 1.95F).setTrackingRange(80).setUpdateInterval(1).setShouldReceiveVelocityUpdates(true); EntityType entry = builder.build(REFERENCE.MODID + ":" + id); @@ -49,6 +61,7 @@ public String getModID() { public MCACompat() { FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(EntityType.class, MCACompat::registerEntities); + FMLJavaModLoadingContext.get().getModEventBus().addListener( MCACompat::registerEntityTypeAttributes); } @Override @@ -70,19 +83,12 @@ public String getAcceptedVersionRange() { @Override public void onInitStep(IInitListener.Step step, ParallelDispatchEvent event) { - - } - - @Override - public void onInitStep(Step step, FMLStateEvent event) { - if (step == Step.PRE_INIT) { - - - if (FMLCommonHandler.instance().getSide().isClient()) { - ClientProxy.registerRenderer(); - OverlayAssignmentLoader.init(((FMLPreInitializationEvent) event).getModConfigurationDirectory()); - OverlayAssignmentLoader.registerSaveCommand(); - } + if (step == Step.CLIENT_SETUP) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> // OverlayAssignmentLoader.init((event).getModConfigurationDirectory()); + // OverlayAssignmentLoader.registerSaveCommand(); + ClientProxy::registerRenderer); + } + if (step == Step.COMMON_SETUP) { MinecraftForge.EVENT_BUS.register(new EventHandlerMCA()); } } diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompatREFERENCE.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompatREFERENCE.java index 46387cd..c6baaf2 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompatREFERENCE.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompatREFERENCE.java @@ -6,11 +6,6 @@ public class MCACompatREFERENCE { - @ObjectHolder("vampirism:player.bite") - static final SoundEvent player_bite = null; - - @ObjectHolder("vampirism:pitchfork") - static final Item pitchfork = null; /** * Check for vampire garlic damage every n ticks diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/ClientProxy.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/ClientProxy.java index 65356b0..3290efc 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/ClientProxy.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/ClientProxy.java @@ -2,14 +2,16 @@ import de.teamlapen.vampirism_integrations.mca.EntityAngryVillagerMCA; import de.teamlapen.vampirism_integrations.mca.EntityConvertedVillagerMCA; -import mca.client.render.RenderVillagerMCA; +import de.teamlapen.vampirism_integrations.mca.MCACompat; +import mca.client.render.VillagerEntityMCARenderer; public class ClientProxy { public static void registerRenderer() { - net.minecraftforge.fml.client.registry.RenderingRegistry.registerEntityRenderingHandler(EntityConvertedVillagerMCA.class, RenderVillagerMCAConverted::new); - net.minecraftforge.fml.client.registry.RenderingRegistry.registerEntityRenderingHandler(EntityAngryVillagerMCA.class, RenderVillagerMCA::new); - + net.minecraftforge.fml.client.registry.RenderingRegistry.registerEntityRenderingHandler(EntityConvertedVillagerMCA.converted_villager_female, RenderVillagerMCAConverted::new); + net.minecraftforge.fml.client.registry.RenderingRegistry.registerEntityRenderingHandler(EntityConvertedVillagerMCA.converted_villager_male, RenderVillagerMCAConverted::new); + net.minecraftforge.fml.client.registry.RenderingRegistry.registerEntityRenderingHandler(EntityAngryVillagerMCA.angry_villager_female, VillagerEntityMCARenderer::new); + net.minecraftforge.fml.client.registry.RenderingRegistry.registerEntityRenderingHandler(EntityAngryVillagerMCA.angry_villager_male, VillagerEntityMCARenderer::new); } diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/LayerVampireFace.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/LayerVampireFace.java index 7ec5a0e..e14e382 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/LayerVampireFace.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/LayerVampireFace.java @@ -1,71 +1,63 @@ -package de.teamlapen.vampirism_integrations.mca.client; - -import de.teamlapen.vampirism_integrations.mca.EntityConvertedVillagerMCA; -import de.teamlapen.vampirism_integrations.util.REFERENCE; -import mca.entity.EntityVillagerMCA; -import net.minecraft.client.model.ModelBiped; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.entity.layers.LayerRenderer; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.tuple.Pair; - -import java.util.HashMap; -import java.util.Map; - -@SideOnly(Side.CLIENT) -public class LayerVampireFace implements LayerRenderer { - - private final RenderVillagerMCAConverted renderer; - - private final ResourceLocation[] eyeOverlays; - private final ResourceLocation[] fangOverlays; - - - LayerVampireFace(RenderVillagerMCAConverted renderer, ResourceLocation overlay) { - this.renderer = renderer; - eyeOverlays = new ResourceLocation[de.teamlapen.vampirism.util.REFERENCE.EYE_TYPE_COUNT]; - for (int i = 0; i < eyeOverlays.length; i++) { - eyeOverlays[i] = new ResourceLocation(REFERENCE.VAMPIRISM_ID + ":textures/entity/vanilla/eyes" + (i) + ".png"); - } - fangOverlays = new ResourceLocation[de.teamlapen.vampirism.util.REFERENCE.FANG_TYPE_COUNT]; - for (int i = 0; i < fangOverlays.length; i++) { - fangOverlays[i] = new ResourceLocation(REFERENCE.VAMPIRISM_ID + ":textures/entity/vanilla/fangs" + i + ".png"); - } - } - - @Override - public void doRenderLayer(EntityConvertedVillagerMCA entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) { - if (!entitylivingbaseIn.isInvisible()) { - ModelBiped biped = (ModelBiped) renderer.getMainModel(); - GlStateManager.pushMatrix(); - if (entitylivingbaseIn.isSneaking()) { - GlStateManager.translate(0.0F, 0.2F, 0.0F); - } - String tex = entitylivingbaseIn.get(EntityVillagerMCA.TEXTURE); - Pair conf = OverlayAssignmentLoader.assignments.computeIfAbsent(tex, k -> Pair.of(0, 0)); - - int eye = conf.getLeft(); - int fang = conf.getRight(); - - if (eye >= 0 && eye < eyeOverlays.length) { - this.renderer.bindTexture(eyeOverlays[eye]); - biped.bipedHead.render(scale); - } - if (fang >= 0 && fang < fangOverlays.length) { - this.renderer.bindTexture(fangOverlays[fang]); - biped.bipedHead.render(scale); - } - - - GlStateManager.popMatrix(); - } - - } - - @Override - public boolean shouldCombineTextures() { - return true; - } -} +//package de.teamlapen.vampirism_integrations.mca.client; +// +//import com.mojang.blaze3d.matrix.MatrixStack; +//import com.mojang.blaze3d.platform.GlStateManager; +//import com.mojang.blaze3d.systems.RenderSystem; +//import de.teamlapen.vampirism_integrations.util.REFERENCE; +//import mca.client.model.VillagerEntityModelMCA; +//import mca.entity.VillagerEntityMCA; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.renderer.IRenderTypeBuffer; +//import net.minecraft.client.renderer.entity.layers.LayerRenderer; +//import net.minecraft.util.ResourceLocation; +//import org.apache.commons.lang3.tuple.Pair; +// +//public class LayerVampireFace extends LayerRenderer> { +// +// private final RenderVillagerMCAConverted renderer; +// +// private final ResourceLocation[] eyeOverlays; +// private final ResourceLocation[] fangOverlays; +// +// +// LayerVampireFace(RenderVillagerMCAConverted renderer, ResourceLocation overlay) { +// super(renderer); +// this.renderer = renderer; +// eyeOverlays = new ResourceLocation[de.teamlapen.vampirism.REFERENCE.EYE_TYPE_COUNT]; +// for (int i = 0; i < eyeOverlays.length; i++) { +// eyeOverlays[i] = new ResourceLocation(REFERENCE.VAMPIRISM_ID + ":textures/entity/vanilla/eyes" + (i) + ".png"); +// } +// fangOverlays = new ResourceLocation[de.teamlapen.vampirism.REFERENCE.FANG_TYPE_COUNT]; +// for (int i = 0; i < fangOverlays.length; i++) { +// fangOverlays[i] = new ResourceLocation(REFERENCE.VAMPIRISM_ID + ":textures/entity/vanilla/fangs" + i + ".png"); +// } +// } +// +// @Override +// public void render(MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int i, VillagerEntityMCA villagerEntityMCA, float v, float v1, float v2, float v3, float v4, float v5) { +// if (!villagerEntityMCA.isInvisible()) { +// VillagerEntityModelMCA biped = renderer.getModel(); +// matrixStack.pushPose(); +// if (villagerEntityMCA.isShiftKeyDown()) { +// matrixStack.translate(0.0F, 0.2F, 0.0F); +// } +// String tex = villagerEntityMCA.get(EntityVillagerMCA.TEXTURE); +// Pair conf = OverlayAssignmentLoader.assignments.computeIfAbsent(tex, k -> Pair.of(0, 0)); +// +// int eye = conf.getLeft(); +// int fang = conf.getRight(); +// +// if (eye >= 0 && eye < eyeOverlays.length) { +// Minecraft.getInstance().getTextureManager().bind(eyeOverlays[eye]); +// biped.bipedHead.render(scale); +// } +// if (fang >= 0 && fang < fangOverlays.length) { +// Minecraft.getInstance().getTextureManager().bind(fangOverlays[eye]); +// biped.bipedHead.render(scale); +// } +// +// +// matrixStack.popPose(); +// } +// } +//} diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/OverlayAssignmentLoader.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/OverlayAssignmentLoader.java index 7fb649b..a85fc24 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/OverlayAssignmentLoader.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/OverlayAssignmentLoader.java @@ -1,15 +1,14 @@ package de.teamlapen.vampirism_integrations.mca.client; -import de.teamlapen.vampirism_integrations.VampirismIntegrationsMod; -import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.text.TextComponentString; -import net.minecraftforge.client.ClientCommandHandler; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; import java.io.*; import java.util.HashMap; @@ -19,7 +18,8 @@ * Load mca skin -> overlay id from file */ public class OverlayAssignmentLoader { - private final static String TAG = "OverlayAssignment"; + private final static Marker TAG = MarkerManager.getMarker("OverlayAssignment"); + private static final Logger LOGGER = LogManager.getLogger(); static Map> assignments; @@ -32,17 +32,17 @@ public static void init(File configDir) { try { assignments = loadAssignments(new InputStreamReader(OverlayAssignmentLoader.class.getResourceAsStream("/mca/skin_overlay_assignment.txt")), "skin_overlay_assignment.txt"); } catch (IOException e) { - VampirismIntegrationsMod.log.bigWarning(TAG, "Could not read mca skin assignments"); - VampirismIntegrationsMod.log.e(TAG, e, "Exception"); + LOGGER.warn(TAG, "Could not read mca skin assignments"); + LOGGER.error(e); } if (assignmentFile.exists()) { try { Map> override = loadAssignments(new FileReader(assignmentFile), assignmentFile.getName()); assignments.putAll(override); - VampirismIntegrationsMod.log.i(TAG, "Successfully loaded additional assignment file"); + LOGGER.info(TAG, "Successfully loaded additional assignment file"); } catch (IOException e) { - VampirismIntegrationsMod.log.e(TAG, "Could not read mca skin assignments from config file %s", assignmentFile.getName()); + LOGGER.error(TAG, "Could not read mca skin assignments from config file {}", assignmentFile.getName()); } } @@ -54,7 +54,7 @@ public static boolean save() { try { return writeBloodValues(new FileWriter(dumpAssignmentFile), assignments, "Generated - Not loaded - Copy to mca_skin_overlay_assignment.txt - MCA Texture -> Eye Fang Overlay assignment. Format: texture=eye,fang. Use -1 for fang or eye to disable"); } catch (IOException e) { - VampirismIntegrationsMod.log.e(TAG, e, "Failed to store mca skin assignments"); + LOGGER.error(TAG, "Failed to store mca skin assignments", e); } } return false; @@ -72,7 +72,7 @@ private static Map> loadAssignments(Reader r, Str if (StringUtils.isBlank(line)) continue; String[] p = line.split("="); if (p.length != 2) { - VampirismIntegrationsMod.log.w(TAG, "Line %s in %s is not formatted properly", line, file); + LOGGER.warn(TAG, "Line {} in {} is not formatted properly", line, file); continue; } String[] p2 = p[1].split(","); @@ -82,7 +82,7 @@ private static Map> loadAssignments(Reader r, Str eye = Integer.parseInt(p2[0]); fang = Integer.parseInt(p2[1]); } catch (NumberFormatException e) { - VampirismIntegrationsMod.log.w(TAG, "Line %s in %s is not formatted properly", line, file); + LOGGER.warn(TAG, "Line {} in {} is not formatted properly", line, file); continue; } map.put(p[0], Pair.of(eye, fang)); @@ -116,7 +116,8 @@ private static boolean writeBloodValues(Writer w, Map { +class RenderVillagerMCAConverted extends VillagerEntityMCARenderer { private final static ResourceLocation overlay = new ResourceLocation(REFERENCE.MODID, "textures/mca/overlay.png"); - RenderVillagerMCAConverted(RenderManager manager) { - super(manager); - this.addLayer(new LayerVampireFace(this, overlay)); + RenderVillagerMCAConverted(EntityRendererManager ctx) { + super(ctx); + //this.addLayer(new LayerVampireFace(this, overlay)); } - - @Override - public void doRender(EntityVillagerMCA entity, double x, double y, double z, float entityYaw, float partialTicks) { - super.doRender(entity, x, y, z, entityYaw, partialTicks); - } } From a451dcd84ad55ef368145c48f93a2318a271b405 Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Wed, 15 Jun 2022 18:19:06 +0200 Subject: [PATCH 3/3] fix vampire face layer --- .../vampirism_integrations/mca/MCACompat.java | 1 - .../mca/client/ClientProxy.java | 1 - .../mca/client/LayerVampireFace.java | 107 +++++-------- .../mca/client/OverlayAssignmentLoader.java | 150 ------------------ .../client/RenderVillagerMCAConverted.java | 8 +- .../resources/mca/skin_overlay_assignment.txt | 7 - 6 files changed, 51 insertions(+), 223 deletions(-) delete mode 100644 src/main/java/de/teamlapen/vampirism_integrations/mca/client/OverlayAssignmentLoader.java delete mode 100644 src/main/resources/mca/skin_overlay_assignment.txt diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java index f76e6a6..06402d3 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/MCACompat.java @@ -6,7 +6,6 @@ import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism_integrations.IInterModeEnqueue; import de.teamlapen.vampirism_integrations.mca.client.ClientProxy; -import de.teamlapen.vampirism_integrations.mca.client.OverlayAssignmentLoader; import de.teamlapen.vampirism_integrations.util.REFERENCE; import mca.entity.EntitiesMCA; import mca.entity.ai.relationship.Gender; diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/ClientProxy.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/ClientProxy.java index 3290efc..3a61ea7 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/ClientProxy.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/ClientProxy.java @@ -2,7 +2,6 @@ import de.teamlapen.vampirism_integrations.mca.EntityAngryVillagerMCA; import de.teamlapen.vampirism_integrations.mca.EntityConvertedVillagerMCA; -import de.teamlapen.vampirism_integrations.mca.MCACompat; import mca.client.render.VillagerEntityMCARenderer; public class ClientProxy { diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/LayerVampireFace.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/LayerVampireFace.java index e14e382..13932d1 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/LayerVampireFace.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/LayerVampireFace.java @@ -1,63 +1,44 @@ -//package de.teamlapen.vampirism_integrations.mca.client; -// -//import com.mojang.blaze3d.matrix.MatrixStack; -//import com.mojang.blaze3d.platform.GlStateManager; -//import com.mojang.blaze3d.systems.RenderSystem; -//import de.teamlapen.vampirism_integrations.util.REFERENCE; -//import mca.client.model.VillagerEntityModelMCA; -//import mca.entity.VillagerEntityMCA; -//import net.minecraft.client.Minecraft; -//import net.minecraft.client.renderer.IRenderTypeBuffer; -//import net.minecraft.client.renderer.entity.layers.LayerRenderer; -//import net.minecraft.util.ResourceLocation; -//import org.apache.commons.lang3.tuple.Pair; -// -//public class LayerVampireFace extends LayerRenderer> { -// -// private final RenderVillagerMCAConverted renderer; -// -// private final ResourceLocation[] eyeOverlays; -// private final ResourceLocation[] fangOverlays; -// -// -// LayerVampireFace(RenderVillagerMCAConverted renderer, ResourceLocation overlay) { -// super(renderer); -// this.renderer = renderer; -// eyeOverlays = new ResourceLocation[de.teamlapen.vampirism.REFERENCE.EYE_TYPE_COUNT]; -// for (int i = 0; i < eyeOverlays.length; i++) { -// eyeOverlays[i] = new ResourceLocation(REFERENCE.VAMPIRISM_ID + ":textures/entity/vanilla/eyes" + (i) + ".png"); -// } -// fangOverlays = new ResourceLocation[de.teamlapen.vampirism.REFERENCE.FANG_TYPE_COUNT]; -// for (int i = 0; i < fangOverlays.length; i++) { -// fangOverlays[i] = new ResourceLocation(REFERENCE.VAMPIRISM_ID + ":textures/entity/vanilla/fangs" + i + ".png"); -// } -// } -// -// @Override -// public void render(MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int i, VillagerEntityMCA villagerEntityMCA, float v, float v1, float v2, float v3, float v4, float v5) { -// if (!villagerEntityMCA.isInvisible()) { -// VillagerEntityModelMCA biped = renderer.getModel(); -// matrixStack.pushPose(); -// if (villagerEntityMCA.isShiftKeyDown()) { -// matrixStack.translate(0.0F, 0.2F, 0.0F); -// } -// String tex = villagerEntityMCA.get(EntityVillagerMCA.TEXTURE); -// Pair conf = OverlayAssignmentLoader.assignments.computeIfAbsent(tex, k -> Pair.of(0, 0)); -// -// int eye = conf.getLeft(); -// int fang = conf.getRight(); -// -// if (eye >= 0 && eye < eyeOverlays.length) { -// Minecraft.getInstance().getTextureManager().bind(eyeOverlays[eye]); -// biped.bipedHead.render(scale); -// } -// if (fang >= 0 && fang < fangOverlays.length) { -// Minecraft.getInstance().getTextureManager().bind(fangOverlays[eye]); -// biped.bipedHead.render(scale); -// } -// -// -// matrixStack.popPose(); -// } -// } -//} +package de.teamlapen.vampirism_integrations.mca.client; + +import de.teamlapen.vampirism_integrations.util.REFERENCE; +import mca.client.model.VillagerEntityModelMCA; +import mca.client.render.layer.VillagerLayer; +import mca.entity.VillagerLike; +import mca.entity.ai.Genetics; +import net.minecraft.client.renderer.entity.IEntityRenderer; +import net.minecraft.entity.MobEntity; +import net.minecraft.util.ResourceLocation; + +public class LayerVampireFace> extends VillagerLayer> { + + private final ResourceLocation[] eyeOverlays; + private final ResourceLocation[] fangOverlays; + + + LayerVampireFace(IEntityRenderer> renderer, VillagerEntityModelMCA model) { + super(renderer, model); + this.eyeOverlays = new ResourceLocation[de.teamlapen.vampirism.REFERENCE.EYE_TYPE_COUNT]; + for (int i = 0; i < this.eyeOverlays.length; i++) { + this.eyeOverlays[i] = new ResourceLocation(REFERENCE.VAMPIRISM_ID + ":textures/entity/vanilla/eyes" + (i) + ".png"); + } + this.fangOverlays = new ResourceLocation[de.teamlapen.vampirism.REFERENCE.FANG_TYPE_COUNT]; + for (int i = 0; i < this.fangOverlays.length; i++) { + this.fangOverlays[i] = new ResourceLocation(REFERENCE.VAMPIRISM_ID + ":textures/entity/vanilla/fangs" + i + ".png"); + } + } + + @Override + protected ResourceLocation getSkin(T villager) { + int totalFaces = this.eyeOverlays.length; + int index = (int)Math.min((float)(totalFaces - 1), Math.max(0.0F, villager.getGenetics().getGene(Genetics.FACE) * (float)totalFaces)); + return eyeOverlays[index]; + } + + @Override + protected ResourceLocation getOverlay(T villager) { + int totalFangs = this.fangOverlays.length; + int index = (int)Math.min((float)(totalFangs - 1), Math.max(0.0F, villager.getGenetics().getGene(Genetics.FACE) * (float)totalFangs)); + return fangOverlays[index]; + } + +} diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/OverlayAssignmentLoader.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/OverlayAssignmentLoader.java deleted file mode 100644 index a85fc24..0000000 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/OverlayAssignmentLoader.java +++ /dev/null @@ -1,150 +0,0 @@ -package de.teamlapen.vampirism_integrations.mca.client; - - -import net.minecraft.command.CommandException; -import net.minecraft.server.MinecraftServer; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.MarkerManager; - -import java.io.*; -import java.util.HashMap; -import java.util.Map; - -/** - * Load mca skin -> overlay id from file - */ -public class OverlayAssignmentLoader { - private final static Marker TAG = MarkerManager.getMarker("OverlayAssignment"); - private static final Logger LOGGER = LogManager.getLogger(); - - - static Map> assignments; - private static File dumpAssignmentFile; - - public static void init(File configDir) { - File assignmentFile = new File(configDir, "vampirism/mca_skin_overlay_assignment.txt"); - dumpAssignmentFile = new File(configDir, "vampirism/mca_skin_overlay_assignment_dump.txt"); - - try { - assignments = loadAssignments(new InputStreamReader(OverlayAssignmentLoader.class.getResourceAsStream("/mca/skin_overlay_assignment.txt")), "skin_overlay_assignment.txt"); - } catch (IOException e) { - LOGGER.warn(TAG, "Could not read mca skin assignments"); - LOGGER.error(e); - } - - if (assignmentFile.exists()) { - try { - Map> override = loadAssignments(new FileReader(assignmentFile), assignmentFile.getName()); - assignments.putAll(override); - LOGGER.info(TAG, "Successfully loaded additional assignment file"); - } catch (IOException e) { - LOGGER.error(TAG, "Could not read mca skin assignments from config file {}", assignmentFile.getName()); - } - } - - } - - public static boolean save() { - if (dumpAssignmentFile != null) { - dumpAssignmentFile.getParentFile().mkdirs(); - try { - return writeBloodValues(new FileWriter(dumpAssignmentFile), assignments, "Generated - Not loaded - Copy to mca_skin_overlay_assignment.txt - MCA Texture -> Eye Fang Overlay assignment. Format: texture=eye,fang. Use -1 for fang or eye to disable"); - } catch (IOException e) { - LOGGER.error(TAG, "Failed to store mca skin assignments", e); - } - } - return false; - } - - - private static Map> loadAssignments(Reader r, String file) throws IOException { - Map> map = new HashMap<>(); - BufferedReader br = null; - try { - br = new BufferedReader(r); - String line; - while ((line = br.readLine()) != null) { - if (line.startsWith("#")) continue; - if (StringUtils.isBlank(line)) continue; - String[] p = line.split("="); - if (p.length != 2) { - LOGGER.warn(TAG, "Line {} in {} is not formatted properly", line, file); - continue; - } - String[] p2 = p[1].split(","); - int eye; - int fang; - try { - eye = Integer.parseInt(p2[0]); - fang = Integer.parseInt(p2[1]); - } catch (NumberFormatException e) { - LOGGER.warn(TAG, "Line {} in {} is not formatted properly", line, file); - continue; - } - map.put(p[0], Pair.of(eye, fang)); - } - } finally { - if (br != null) { - br.close(); - } - r.close(); - } - return map; - - } - - private static boolean writeBloodValues(Writer w, Map> values, String comment) throws IOException { - BufferedWriter bw = null; - try { - bw = new BufferedWriter(w); - bw.write('#'); - bw.write(comment); - bw.newLine(); - for (Map.Entry> entry : values.entrySet()) { - bw.write(entry.getKey()); - bw.write('='); - Pair v = entry.getValue(); - bw.write(String.valueOf(v.getLeft())); - bw.write(','); - bw.write(String.valueOf((v.getRight()))); - bw.newLine(); - } - bw.flush(); - return true; - } catch (IOException e) { - LOGGER.error(TAG, "Failed to write mca overlay assignments ({})", comment); - LOGGER.error(e); - } finally { - if (bw != null) { - bw.close(); - } - w.close(); - } - return false; - } - -// public static void registerSaveCommand() { -// ClientCommandHandler.instance.registerCommand(new CommandBase() { -// @Override -// public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { -// if (OverlayAssignmentLoader.save()) { -// sender.sendMessage(new TextComponentString("Successfully stored mca skin assignments to vampirism config directory")); -// } -// } -// -// @Override -// public String getName() { -// return "vampirism-mca-save-assignment"; -// } -// -// @Override -// public String getUsage(ICommandSender sender) { -// return getName(); -// } -// }); -// } -} diff --git a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/RenderVillagerMCAConverted.java b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/RenderVillagerMCAConverted.java index 391303a..b8d6edd 100644 --- a/src/main/java/de/teamlapen/vampirism_integrations/mca/client/RenderVillagerMCAConverted.java +++ b/src/main/java/de/teamlapen/vampirism_integrations/mca/client/RenderVillagerMCAConverted.java @@ -6,6 +6,9 @@ import mca.client.render.VillagerEntityMCARenderer; import mca.client.render.VillagerLikeEntityMCARenderer; import mca.entity.VillagerEntityMCA; +import mca.util.compat.model.Dilation; +import mca.util.compat.model.ModelData; +import mca.util.compat.model.TexturedModelData; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.util.ResourceLocation; @@ -14,7 +17,10 @@ class RenderVillagerMCAConverted extends VillagerEntityMCARenderer { RenderVillagerMCAConverted(EntityRendererManager ctx) { super(ctx); - //this.addLayer(new LayerVampireFace(this, overlay)); + this.addLayer(new LayerVampireFace<>(this, createModel(VillagerEntityModelMCA.bodyData(new Dilation(0.01F))).hideWears())); + } + private static VillagerEntityModelMCA createModel(ModelData data) { + return new VillagerEntityModelMCA<>(TexturedModelData.of(data, 64, 64).createModel()); } } diff --git a/src/main/resources/mca/skin_overlay_assignment.txt b/src/main/resources/mca/skin_overlay_assignment.txt deleted file mode 100644 index fcbc3b1..0000000 --- a/src/main/resources/mca/skin_overlay_assignment.txt +++ /dev/null @@ -1,7 +0,0 @@ -#MCA Texture -> Eye Fang Overlay assignment. Format: texture=eye,fang. Use -1 for fang or eye to disable -mca:skins/female/baker/bakerf1_converted.png=2,3 -mca:skins/female/baker/bakerf2_converted.png=1,4 -mca:skins/female/baker/bakerf3_converted.png=11,0 -mca:skins/female/baker/bakerf4_converted.png=11,0 -mca:skins/female/baker/bakerf5_converted.png=8,-1 -mca:skins/female/baker/bakerf6_converted.png=5,0 \ No newline at end of file