Search in sources :

Example 1 with AdapterIRitual

use of com.bewitchment.common.ritual.AdapterIRitual in project Bewitchment by Um-Mitternacht.

the class TileEntityGlyph method startRitual.

public void startRitual(EntityPlayer player) {
    if (player.getEntityWorld().isRemote)
        return;
    List<EntityItem> itemsOnGround = getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(getPos()).grow(3, 0, 3));
    List<ItemStack> recipe = itemsOnGround.stream().map(i -> i.getItem()).collect(Collectors.toList());
    for (AdapterIRitual rit : AdapterIRitual.REGISTRY) {
        // Check every ritual
        if (rit.isValidInput(recipe, hasCircles(rit))) {
            // Check if circles and items match
            if (rit.isValid(player, world, pos, recipe)) {
                // Checks of extra conditions are met
                if (consumePower(rit.getRequiredStartingPower())) {
                    // Check if there is enough starting power (and uses it in case there is)
                    // The following block saves all the item used in the input inside the nbt
                    // vvvvvv
                    this.ritualData = new NBTTagCompound();
                    NBTTagList itemsUsed = new NBTTagList();
                    itemsOnGround.forEach(ei -> {
                        NBTTagCompound item = new NBTTagCompound();
                        ei.getItem().writeToNBT(item);
                        itemsUsed.appendTag(item);
                        ei.setDead();
                    });
                    ritualData.setTag("itemsUsed", itemsUsed);
                    // ^^^^^
                    // Sets the ritual up
                    this.ritual = rit;
                    this.entityPlayer = player.getPersistentID();
                    this.cooldown = 1;
                    ritual.onStarted(player, this, getWorld(), getPos(), ritualData);
                    player.sendStatusMessage(new TextComponentTranslation("ritual." + rit.getRegistryName().toString().replace(':', '.') + ".name", new Object[0]), true);
                    world.notifyBlockUpdate(getPos(), world.getBlockState(getPos()), world.getBlockState(getPos()), 3);
                    markDirty();
                    return;
                }
                player.sendStatusMessage(new TextComponentTranslation("ritual.failure.power", new Object[0]), true);
                return;
            }
            player.sendStatusMessage(new TextComponentTranslation("ritual.failure.precondition", new Object[0]), true);
            return;
        }
    }
    if (!itemsOnGround.isEmpty())
        player.sendStatusMessage(new TextComponentTranslation("ritual.failure.unknown", new Object[0]), true);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) BlockCircleGlyph(com.bewitchment.common.block.tools.BlockCircleGlyph) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Tuple(net.minecraft.util.Tuple) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) NBTTagString(net.minecraft.nbt.NBTTagString) Collectors(java.util.stream.Collectors) EnumGlyphType(com.bewitchment.api.ritual.EnumGlyphType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ArrayList(java.util.ArrayList) ModBlocks(com.bewitchment.common.block.ModBlocks) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) NBT(net.minecraftforge.common.util.Constants.NBT) AdapterIRitual(com.bewitchment.common.ritual.AdapterIRitual) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ITickable(net.minecraft.util.ITickable) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagList(net.minecraft.nbt.NBTTagList) AdapterIRitual(com.bewitchment.common.ritual.AdapterIRitual) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EnumGlyphType (com.bewitchment.api.ritual.EnumGlyphType)1 ModBlocks (com.bewitchment.common.block.ModBlocks)1 BlockCircleGlyph (com.bewitchment.common.block.tools.BlockCircleGlyph)1 AdapterIRitual (com.bewitchment.common.ritual.AdapterIRitual)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 NBTTagString (net.minecraft.nbt.NBTTagString)1 ITickable (net.minecraft.util.ITickable)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Tuple (net.minecraft.util.Tuple)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1