Rewrite metamorphosis to work with husks/strays and skeleton minions
This commit is contained in:
@@ -1,23 +1,31 @@
|
|||||||
package electroblob.wizardry.spell;
|
package electroblob.wizardry.spell;
|
||||||
|
|
||||||
|
import com.google.common.collect.BiMap;
|
||||||
|
import com.google.common.collect.HashBiMap;
|
||||||
|
|
||||||
import electroblob.wizardry.Wizardry;
|
import electroblob.wizardry.Wizardry;
|
||||||
import electroblob.wizardry.constants.Element;
|
import electroblob.wizardry.constants.Element;
|
||||||
import electroblob.wizardry.constants.SpellType;
|
import electroblob.wizardry.constants.SpellType;
|
||||||
import electroblob.wizardry.constants.Tier;
|
import electroblob.wizardry.constants.Tier;
|
||||||
|
import electroblob.wizardry.entity.living.EntitySkeletonMinion;
|
||||||
|
import electroblob.wizardry.entity.living.EntityWitherSkeletonMinion;
|
||||||
import electroblob.wizardry.registry.WizardryItems;
|
import electroblob.wizardry.registry.WizardryItems;
|
||||||
import electroblob.wizardry.registry.WizardrySounds;
|
import electroblob.wizardry.registry.WizardrySounds;
|
||||||
import electroblob.wizardry.util.SpellModifiers;
|
import electroblob.wizardry.util.SpellModifiers;
|
||||||
import electroblob.wizardry.util.WizardryParticleType;
|
import electroblob.wizardry.util.WizardryParticleType;
|
||||||
import electroblob.wizardry.util.WizardryUtilities;
|
import electroblob.wizardry.util.WizardryUtilities;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLiving;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.monster.EntityCaveSpider;
|
import net.minecraft.entity.monster.EntityCaveSpider;
|
||||||
|
import net.minecraft.entity.monster.EntityHusk;
|
||||||
import net.minecraft.entity.monster.EntityMagmaCube;
|
import net.minecraft.entity.monster.EntityMagmaCube;
|
||||||
import net.minecraft.entity.monster.EntityPigZombie;
|
import net.minecraft.entity.monster.EntityPigZombie;
|
||||||
import net.minecraft.entity.monster.EntitySkeleton;
|
import net.minecraft.entity.monster.EntitySkeleton;
|
||||||
import net.minecraft.entity.monster.EntitySlime;
|
import net.minecraft.entity.monster.EntitySlime;
|
||||||
import net.minecraft.entity.monster.EntitySpider;
|
import net.minecraft.entity.monster.EntitySpider;
|
||||||
|
import net.minecraft.entity.monster.EntityStray;
|
||||||
import net.minecraft.entity.monster.EntityWitherSkeleton;
|
import net.minecraft.entity.monster.EntityWitherSkeleton;
|
||||||
|
import net.minecraft.entity.monster.EntityZombie;
|
||||||
import net.minecraft.entity.passive.EntityBat;
|
import net.minecraft.entity.passive.EntityBat;
|
||||||
import net.minecraft.entity.passive.EntityChicken;
|
import net.minecraft.entity.passive.EntityChicken;
|
||||||
import net.minecraft.entity.passive.EntityCow;
|
import net.minecraft.entity.passive.EntityCow;
|
||||||
@@ -32,8 +40,30 @@ import net.minecraft.world.World;
|
|||||||
|
|
||||||
public class Metamorphosis extends Spell {
|
public class Metamorphosis extends Spell {
|
||||||
|
|
||||||
|
public static final BiMap<Class<? extends EntityLivingBase>, Class<? extends EntityLivingBase>> TRANSFORMATIONS = HashBiMap.create();
|
||||||
|
|
||||||
public Metamorphosis(){
|
public Metamorphosis(){
|
||||||
super(Tier.APPRENTICE, 15, Element.NECROMANCY, "metamorphosis", SpellType.UTILITY, 30, EnumAction.NONE, false);
|
super(Tier.APPRENTICE, 15, Element.NECROMANCY, "metamorphosis", SpellType.UTILITY, 30, EnumAction.NONE, false);
|
||||||
|
|
||||||
|
addTransformation(EntityPig.class, EntityPigZombie.class);
|
||||||
|
addTransformation(EntityCow.class, EntityMooshroom.class);
|
||||||
|
addTransformation(EntityChicken.class, EntityBat.class);
|
||||||
|
addTransformation(EntityZombie.class, EntityHusk.class);
|
||||||
|
addTransformation(EntitySkeleton.class, EntityWitherSkeleton.class, EntityStray.class);
|
||||||
|
addTransformation(EntitySpider.class, EntityCaveSpider.class);
|
||||||
|
addTransformation(EntitySlime.class, EntityMagmaCube.class);
|
||||||
|
addTransformation(EntitySkeletonMinion.class, EntityWitherSkeletonMinion.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adds circular mappings between the given entity classes to the transformations map. In other words, given an
|
||||||
|
* array of entity classes [A, B, C, D], adds mappings A -> B, B -> C, C -> D and D -> A. */
|
||||||
|
@SafeVarargs
|
||||||
|
public static void addTransformation(Class<? extends EntityLivingBase>... entities){
|
||||||
|
Class<? extends EntityLivingBase> previousEntity = entities[entities.length - 1];
|
||||||
|
for(Class<? extends EntityLivingBase> entity : entities){
|
||||||
|
TRANSFORMATIONS.put(previousEntity, entity);
|
||||||
|
previousEntity = entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,49 +81,34 @@ public class Metamorphosis extends Spell {
|
|||||||
double yPos = entityHit.posY;
|
double yPos = entityHit.posY;
|
||||||
double zPos = entityHit.posZ;
|
double zPos = entityHit.posZ;
|
||||||
|
|
||||||
EntityLiving newEntity = null;
|
// Sneaking allows the entities to be cycled through in the other direction.
|
||||||
|
Class<? extends EntityLivingBase> newEntityClass = caster.isSneaking() ?
|
||||||
|
TRANSFORMATIONS.inverse().get(entityHit.getClass()) : TRANSFORMATIONS.get(entityHit.getClass());
|
||||||
|
|
||||||
// IDEA: Interaction with husks/strays?
|
if(newEntityClass == null) return false;
|
||||||
// TODO: Replace with a bimap or something.
|
|
||||||
if(entityHit instanceof EntityPig){
|
EntityLivingBase newEntity = null;
|
||||||
newEntity = new EntityPigZombie(world);
|
|
||||||
}else if(entityHit instanceof EntityPigZombie){
|
try {
|
||||||
newEntity = new EntityPig(world);
|
newEntity = newEntityClass.getConstructor(World.class).newInstance(world);
|
||||||
}else if(entityHit instanceof EntitySkeleton){
|
} catch (Exception e){
|
||||||
newEntity = new EntityWitherSkeleton(world);
|
Wizardry.logger.error("Error while attempting to transform entity " + entityHit.getClass() + " to entity " + newEntityClass);
|
||||||
}else if(entityHit instanceof EntityWitherSkeleton){
|
e.printStackTrace();
|
||||||
newEntity = new EntitySkeleton(world);
|
|
||||||
}else if(entityHit instanceof EntityCow && !(entityHit instanceof EntityMooshroom)){
|
|
||||||
newEntity = new EntityMooshroom(world);
|
|
||||||
}else if(entityHit instanceof EntityMooshroom){
|
|
||||||
newEntity = new EntityCow(world);
|
|
||||||
}else if(entityHit instanceof EntityChicken){
|
|
||||||
newEntity = new EntityBat(world);
|
|
||||||
}else if(entityHit instanceof EntityBat){
|
|
||||||
newEntity = new EntityChicken(world);
|
|
||||||
}else if(entityHit instanceof EntitySlime && !(entityHit instanceof EntityMagmaCube)){
|
|
||||||
newEntity = new EntityMagmaCube(world);
|
|
||||||
}else if(entityHit instanceof EntityMagmaCube){
|
|
||||||
newEntity = new EntitySlime(world);
|
|
||||||
}else if(entityHit instanceof EntitySpider && !(entityHit instanceof EntityCaveSpider)){
|
|
||||||
newEntity = new EntityCaveSpider(world);
|
|
||||||
}else if(entityHit instanceof EntityCaveSpider){
|
|
||||||
newEntity = new EntitySpider(world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newEntity != null){
|
if(newEntity == null) return false;
|
||||||
|
|
||||||
if(!world.isRemote && newEntity != null){
|
if(!world.isRemote){
|
||||||
// Transfers attributes from the old entity to the new one.
|
// Transfers attributes from the old entity to the new one.
|
||||||
newEntity.setHealth(((EntityLiving)entityHit).getHealth());
|
newEntity.setHealth(((EntityLivingBase)entityHit).getHealth());
|
||||||
// newEntity.writeToNBT(entityHit.getEntityData());
|
newEntity.readFromNBT(entityHit.getEntityData());
|
||||||
|
|
||||||
entityHit.setDead();
|
entityHit.setDead();
|
||||||
newEntity.setPosition(xPos, yPos, zPos);
|
newEntity.setPosition(xPos, yPos, zPos);
|
||||||
world.spawnEntity(newEntity);
|
world.spawnEntity(newEntity);
|
||||||
}
|
|
||||||
|
|
||||||
if(world.isRemote){
|
}else{
|
||||||
|
|
||||||
for(int i = 1; i < (int)(25 * modifiers.get(WizardryItems.range_upgrade)); i += 2){
|
for(int i = 1; i < (int)(25 * modifiers.get(WizardryItems.range_upgrade)); i += 2){
|
||||||
// I figured it out! when on client side, entityplayer.posY is at the eyes, not the feet!
|
// I figured it out! when on client side, entityplayer.posY is at the eyes, not the feet!
|
||||||
double x1 = caster.posX + look.x * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
|
double x1 = caster.posX + look.x * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
|
||||||
@@ -114,7 +129,6 @@ public class Metamorphosis extends Spell {
|
|||||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_DEFLECTION, 0.5F, 0.8f);
|
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_DEFLECTION, 0.5F, 0.8f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user