Fancied up the rendering of the Mob Sacrifice array, as well as added more behaviour

This commit is contained in:
WayofTime 2018-05-15 12:40:00 -04:00
parent f563da152e
commit edf4564a07
2 changed files with 105 additions and 56 deletions

View file

@ -11,13 +11,16 @@ import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import WayofTime.bloodmagic.api.impl.BloodMagicAPI;
@ -30,6 +33,8 @@ public class AlchemyArrayEffectMobSacrifice extends AlchemyArrayEffect
{
public static final AreaDescriptor itemDescriptor = new AreaDescriptor.Rectangle(new BlockPos(-5, -5, -5), 11);
public static final AreaDescriptor mobDescriptor = new AreaDescriptor.Rectangle(new BlockPos(-5, -5, -5), 11);
public int craftTime = 0;
public static final int REQUIRED_CRAFT_TIME = 200;
public AlchemyArrayEffectMobSacrifice(String key)
{
@ -54,84 +59,128 @@ public class AlchemyArrayEffectMobSacrifice extends AlchemyArrayEffect
}
}
if (!world.isRemote)
//We need to do the check on both sides to correctly do particles.
if (ticksActive >= 200)
{
if (ticksActive >= 200)
BlockPos pos = tile.getPos();
List<EntityItem> itemList = world.getEntitiesWithinAABB(EntityItem.class, itemDescriptor.getAABB(pos));
List<ItemStack> inputList = new ArrayList<ItemStack>();
for (EntityItem entityItem : itemList)
{
BlockPos pos = tile.getPos();
List<EntityItem> itemList = world.getEntitiesWithinAABB(EntityItem.class, itemDescriptor.getAABB(pos));
List<ItemStack> inputList = new ArrayList<ItemStack>();
for (EntityItem entityItem : itemList)
if (entityItem.isDead || entityItem.getItem().isEmpty())
{
if (entityItem.isDead || entityItem.getItem().isEmpty())
{
continue;
}
inputList.add(entityItem.getItem().copy());
continue;
}
if (inputList.isEmpty())
inputList.add(entityItem.getItem().copy());
}
if (inputList.isEmpty())
{
return false;
}
if (inputList.size() == 1) //TODO: Test if it is a something that can be filled with Soul Breath
{
}
RecipeSacrificeCraft recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getSacrificeCraft(inputList);
if (recipe != null)
{
double healthRequired = recipe.getHealthRequired();
double healthAvailable = 0;
List<EntityLivingBase> livingEntities = world.getEntitiesWithinAABB(EntityLivingBase.class, mobDescriptor.getAABB(pos));
for (EntityLivingBase living : livingEntities)
{
double health = getEffectiveHealth(living);
if (health > 0)
{
healthAvailable += health;
}
}
if (healthAvailable < healthRequired)
{
craftTime = 0;
return false;
}
if (inputList.size() == 1) //TODO: Test if it is a something that can be filled with Soul Breath
craftTime++;
if (craftTime >= REQUIRED_CRAFT_TIME)
{
if (!world.isRemote)
{
for (EntityLivingBase living : livingEntities)
{
double health = getEffectiveHealth(living);
if (healthAvailable > 0)
{
healthAvailable -= health;
living.getEntityWorld().playSound(null, living.posX, living.posY, living.posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (living.getEntityWorld().rand.nextFloat() - living.getEntityWorld().rand.nextFloat()) * 0.8F);
living.setHealth(-1);
living.onDeath(DamageSourceBloodMagic.INSTANCE);
}
}
if (healthAvailable <= 0)
{
break;
}
}
RecipeSacrificeCraft recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getSacrificeCraft(inputList);
if (recipe != null)
for (EntityItem itemEntity : itemList)
{
itemEntity.getItem().setCount(itemEntity.getItem().getCount() - 1);
if (itemEntity.getItem().isEmpty()) //TODO: Check container
{
itemEntity.setDead();
}
}
world.spawnEntity(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 2.5, pos.getZ() + 0.5, recipe.getOutput()));
craftTime = 0;
}
} else
{
double healthRequired = recipe.getHealthRequired();
double healthAvailable = 0;
List<EntityLivingBase> livingEntities = world.getEntitiesWithinAABB(EntityLivingBase.class, mobDescriptor.getAABB(pos));
for (EntityLivingBase living : livingEntities)
if (world.isRemote)
{
double health = getEffectiveHealth(living);
if (health > 0)
Vec3d spawnPosition = new Vec3d(pos.getX() + 0.5, pos.getY() + 2.5, pos.getZ() + 0.5);
for (EntityItem itemEntity : itemList)
{
healthAvailable += health;
}
}
ItemStack stack = itemEntity.getItem();
double velocityFactor = 0.1;
if (healthAvailable < healthRequired)
{
return false;
}
Vec3d itemPosition = new Vec3d(itemEntity.posX, itemEntity.posY + 0.5, itemEntity.posZ);
Vec3d velVec1 = new Vec3d((world.rand.nextDouble() - 0.5) * velocityFactor, (world.rand.nextDouble() - 0.5) * velocityFactor, (world.rand.nextDouble() - 0.5) * velocityFactor);
// Vec3d velVec2 = new Vec3d((world.rand.nextDouble() - 0.5) * velocityFactor, (world.rand.nextDouble()) * velocityFactor, (world.rand.nextDouble() - 0.5) * velocityFactor);
for (EntityLivingBase living : livingEntities)
{
double health = getEffectiveHealth(living);
if (health > 0)
{
healthAvailable -= health;
living.getEntityWorld().playSound(null, living.posX, living.posY, living.posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (living.getEntityWorld().rand.nextFloat() - living.getEntityWorld().rand.nextFloat()) * 0.8F);
living.setHealth(-1);
living.onDeath(DamageSourceBloodMagic.INSTANCE);
// vec3d1 = vec3d1.addVector(this.posX, this.posY + (double)this.getEyeHeight(), this.posZ);
// if (this.world instanceof WorldServer) //Forge: Fix MC-2518 spawnParticle is nooped on server, need to use server specific variant
// ((WorldServer)this.world).spawnParticle(EnumParticleTypes.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, 0, vec3d.x, vec3d.y + 0.05D, vec3d.z, 0.0D, Item.getIdFromItem(stack.getItem()), stack.getMetadata());
// else //Fix the fact that spawning ItemCrack uses TWO arguments.
world.spawnParticle(EnumParticleTypes.ITEM_CRACK, itemPosition.x + (spawnPosition.x - itemPosition.x) * craftTime / REQUIRED_CRAFT_TIME, itemPosition.y + (spawnPosition.y - itemPosition.y) * craftTime / REQUIRED_CRAFT_TIME, itemPosition.z + (spawnPosition.z - itemPosition.z) * craftTime / REQUIRED_CRAFT_TIME, velVec1.x, velVec1.y, velVec1.z, Item.getIdFromItem(stack.getItem()), stack.getMetadata());
// world.spawnParticle(EnumParticleTypes.ITEM_CRACK, spawnPosition.x, spawnPosition.y, spawnPosition.z, velVec2.x, velVec2.y, velVec2.z, Item.getIdFromItem(stack.getItem()), stack.getMetadata());
}
if (healthAvailable <= 0)
for (EntityLivingBase living : livingEntities)
{
break;
double health = getEffectiveHealth(living);
if (health <= 0)
{
continue;
}
double d0 = (double) living.posX + (world.rand.nextDouble() - 0.5D) * 0.5D;
double d1 = (double) living.posY + 0.5D + (world.rand.nextDouble() - 0.5D) * 1D;
double d2 = (double) living.posZ + (world.rand.nextDouble() - 0.5D) * 0.5D;
world.spawnParticle(EnumParticleTypes.SPELL_MOB, d0, d1, d2, 1D, 0.0D, 0.0D);
}
}
for (EntityItem itemEntity : itemList)
{
itemEntity.getItem().setCount(itemEntity.getItem().getCount() - 1);
if (itemEntity.getItem().isEmpty()) //TODO: Check container
{
itemEntity.setDead();
}
}
world.spawnEntity(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, recipe.getOutput()));
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 44 KiB