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);
}
Aggregations